import "package:shared/data.dart";

import "package:flutter/material.dart" show TimeOfDay;

extension type TripID(String id) { }

class Trip {
  final List<TripStop> stops;
  final String path;
  final String name;
  final String abbrev;
  final String polyline;

  const Trip({
    required this.stops,
    required this.path,
    required this.name,
    required this.abbrev,
    required this.polyline,
  });

  Trip.fromJson(Json json) :
    stops = [
      for (final stop in json["stops"])
        TripStop.fromJson(stop),
    ],
    path = json["path"],
    name = json["name"],
    abbrev = json["abbrev"],
    polyline = json["polyline"];
}

class TripStop {
  final double lat;
  final double long;
  // final List<ScheduledTime> times;
  // For testing, use this:
  final String time;

  const TripStop({
    required this.lat,
    required this.long,
    // required this.times,
    required this.time,
  });

  TripStop.fromJson(Json json) :
    lat = json["latitude"],
    long = json["longitude"],
    time = json["time"];
    // times = [
    //   for (final time in json["times"])
    //     ScheduledTime.fromJson(time),
    // ];
}

class ScheduledTime {
  static const weekdays = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];

  final String weekday;
  final TimeOfDay timeOfDay;

  const ScheduledTime({
    required this.weekday,
    required this.timeOfDay,
  });

  factory ScheduledTime.fromJson(Json json) {
    final weekday = json["dotw"];
    final [hour, minute] = (json["time"] as String).split(":");
    final timeOfDay = TimeOfDay(hour: int.parse(hour), minute: int.parse(minute));
    return ScheduledTime(weekday: weekday, timeOfDay: timeOfDay);
  }
}

class PathTrip {
  final String polyline;
  PathTrip.fromJson(Json json) :
    polyline = json["polyline"];
}
