aboutsummaryrefslogtreecommitdiff
path: root/src/Enmarcha.Backend/Types/Arrivals/Arrival.cs
blob: 81811c20faa30f3ad80b4ebeeca7147aac79aaec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System.Text.Json.Serialization;
using Enmarcha.Sources.OpenTripPlannerGql.Queries;

namespace Enmarcha.Backend.Types.Arrivals;

public class Arrival
{
    [JsonPropertyName("tripId")] public required string TripId { get; set; }

    [JsonPropertyName("route")] public required RouteInfo Route { get; set; }

    [JsonPropertyName("headsign")] public required HeadsignInfo Headsign { get; set; }

    [JsonPropertyName("estimate")] public required ArrivalDetails Estimate { get; set; }

    [JsonPropertyName("delay")] public DelayBadge? Delay { get; set; }

    [JsonPropertyName("shift")] public ShiftBadge? Shift { get; set; }

    [JsonPropertyName("shape")] public object? Shape { get; set; }

    [JsonPropertyName("currentPosition")] public Position? CurrentPosition { get; set; }

    [JsonPropertyName("operator")] public string? Operator { get; set; }
    [JsonPropertyName("operation")] public VehicleOperation Operation { get; set; } = VehicleOperation.PickupDropoff;


    [JsonPropertyName("vehicleInformation")]
    public VehicleBadge? VehicleInformation { get; set; }

    [JsonPropertyName("patternId")] public string? PatternId { get; set; }

    [JsonIgnore]
    public List<string> NextStops { get; set; } = [];

    [JsonIgnore]
    public ArrivalsAtStopResponse.Arrival? RawOtpTrip { get; set; }

    [JsonIgnore] public bool Delete { get; set; }
}

public enum VehicleOperation
{
    [JsonStringEnumMemberName("pickup_dropoff")]
    PickupDropoff = 0,
    [JsonStringEnumMemberName("pickup_only")]
    PickupOnly = 1,
    [JsonStringEnumMemberName("dropoff_only")]
    DropoffOnly = 2
}

public class RouteInfo
{
    [JsonPropertyName("gtfsId")] public required string GtfsId { get; set; }

    public string RouteIdInGtfs => GtfsId.Split(':', 2)[1];

    [JsonPropertyName("shortName")] public required string ShortName { get; set; }

    [JsonPropertyName("colour")] public required string Colour { get; set; }

    [JsonPropertyName("textColour")] public required string TextColour { get; set; }
}

public class HeadsignInfo
{
    [JsonPropertyName("badge")] public string? Badge { get; set; }

    [JsonPropertyName("destination")] public required string Destination { get; set; }

    [JsonPropertyName("marquee")] public string? Marquee { get; set; }
}

public class ArrivalDetails
{
    [JsonPropertyName("minutes")] public required int Minutes { get; set; }

    [JsonPropertyName("precision")] public ArrivalPrecision Precision { get; set; } = ArrivalPrecision.Scheduled;
}

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum ArrivalPrecision
{
    [JsonStringEnumMemberName("confident")]
    Confident = 0,
    [JsonStringEnumMemberName("unsure")] Unsure = 1,

    [JsonStringEnumMemberName("scheduled")]
    Scheduled = 2,
    [JsonStringEnumMemberName("past")] Past = 3
}

public class DelayBadge
{
    [JsonPropertyName("minutes")] public int Minutes { get; set; }
}

public class ShiftBadge
{
    [JsonPropertyName("shiftName")] public required string ShiftName { get; set; }

    [JsonPropertyName("shiftTrip")] public required string ShiftTrip { get; set; }
}

public class VehicleBadge
{
    [JsonPropertyName("identifier")] public required string Identifier { get; set; }

    [JsonPropertyName("make")] public string? Make { get; set; }
    [JsonPropertyName("model")] public string? Model { get; set; }
    [JsonPropertyName("kind")] public string? Kind { get; set; }
    [JsonPropertyName("year")] public string? Year { get; set; }


}