aboutsummaryrefslogtreecommitdiff
path: root/src/Enmarcha.Sources.OpenTripPlannerGql/Queries/RouteDetailsContent.cs
blob: 59a09918b95fca7368006f4103e932b65ea12c9c (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
using System.Globalization;
using System.Text.Json.Serialization;

namespace Enmarcha.Sources.OpenTripPlannerGql.Queries;

public class RouteDetailsContent : IGraphRequest<RouteDetailsContent.Args>
{
    public record Args(string Id, string ServiceDate);

    public static string Query(Args args)
    {
        return string.Create(CultureInfo.InvariantCulture, $$"""
        query Query {
          route(id: "{{args.Id}}") {
            gtfsId
            shortName
            longName
            color
            textColor
            agency {
              name
            }

            patterns {
              id
              name
              headsign
              directionId
              code
              semanticHash

              patternGeometry {
                points
              }

              stops {
                gtfsId
                code
                name
                lat
                lon
              }

              tripsForDate(serviceDate: "{{args.ServiceDate}}") {
                stoptimes {
                  scheduledDeparture
                }
              }
            }
          }
        }
        """);
    }
}

public class RouteDetailsResponse : AbstractGraphResponse
{
    [JsonPropertyName("route")] public RouteItem? Route { get; set; }

    public class RouteItem
    {
        [JsonPropertyName("gtfsId")] public string? GtfsId { get; set; }
        [JsonPropertyName("shortName")] public string? ShortName { get; set; }
        [JsonPropertyName("longName")] public string? LongName { get; set; }
        [JsonPropertyName("color")] public string? Color { get; set; }
        [JsonPropertyName("textColor")] public string? TextColor { get; set; }
        [JsonPropertyName("agency")] public AgencyItem? Agency { get; set; }
        [JsonPropertyName("patterns")] public List<PatternItem> Patterns { get; set; } = [];
    }

    public class AgencyItem
    {
        [JsonPropertyName("name")] public string? Name { get; set; }
    }

    public class PatternItem
    {
        [JsonPropertyName("id")] public required string Id { get; set; }
        [JsonPropertyName("name")] public string? Name { get; set; }
        [JsonPropertyName("headsign")] public string? Headsign { get; set; }
        [JsonPropertyName("directionId")] public int DirectionId { get; set; }
        [JsonPropertyName("code")] public string? Code { get; set; }
        [JsonPropertyName("semanticHash")] public string? SemanticHash { get; set; }
        [JsonPropertyName("patternGeometry")] public GeometryItem? PatternGeometry { get; set; }
        [JsonPropertyName("stops")] public List<StopItem> Stops { get; set; } = [];
        [JsonPropertyName("tripsForDate")] public List<TripItem> TripsForDate { get; set; } = [];
    }

    public class GeometryItem
    {
        [JsonPropertyName("points")] public string? Points { get; set; }
    }

    public class StopItem
    {
        [JsonPropertyName("gtfsId")] public required string GtfsId { get; set; }
        [JsonPropertyName("code")] public string? Code { get; set; }
        [JsonPropertyName("name")] public required string Name { get; set; }
        [JsonPropertyName("lat")] public double Lat { get; set; }
        [JsonPropertyName("lon")] public double Lon { get; set; }
    }

    public class TripItem
    {
        [JsonPropertyName("stoptimes")] public List<StoptimeItem> Stoptimes { get; set; } = [];
    }

    public class StoptimeItem
    {
        [JsonPropertyName("scheduledDeparture")] public int ScheduledDeparture { get; set; }
    }
}