# SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
# SPDX-License-Identifier: CC0-1.0

query journeys(
  $fromLat: Float!,
  $fromLon: Float!,
  $toLat: Float!,
  $toLon: Float!,
  $dateTime: DateTime!,
  $arriveBy: Boolean!,
  $maxResults: Int!,
  $lang: Locale!,
  $withIntermediateStops: Boolean!,
  $withPaths: Boolean!
  $allowBikeRental: Boolean!
  $modes: Modes!
) {
  plan: trip (
        from: { coordinates: { latitude: $fromLat, longitude: $fromLon } }
        to:   { coordinates: { latitude: $toLat,   longitude: $toLon } }
        dateTime: $dateTime
        arriveBy: $arriveBy
        numTripPatterns: $maxResults
        locale: $lang
        useBikeRentalAvailabilityInformation: $allowBikeRental
        modes: $modes
    ) {
    itineraries: tripPatterns {
      legs {
        startTime: aimedStartTime
        endTime: aimedEndTime
        realTime: realtime
        expectedStartTime
        expectedEndTime
        distance
        mode
        transitLeg: ride
        rentedBike
        from: fromPlace { ...locationFragment }
        to: toPlace { ...locationFragment }
        fromStoptime: fromEstimatedCall { ...estimatedCallFragment }
        toStoptime: toEstimatedCall { ...estimatedCallFragment }
        trip: serviceJourney {
            id
            route: line {
                presentation {
                    color: colour
                    textColor: textColour
                }
                transportMode
                type: transportSubmode
                shortName: publicCode
                name
                agency: operator {
                    name
                    url
                }
                alerts: situations {
                    alertHeaderTextTranslations: summary {
                        language
                        text: value
                    }
                    alertDescriptionTextTranslations: description {
                        language
                        text: value
                    }
                }
            }
            bikesAllowed
            tripShortName: publicCode
            wheelchairAccessible
        }
        intermediateStops: intermediateEstimatedCalls @include(if: $withIntermediateStops) {
          stop: quay {
            id
            name
            platformCode: publicCode
            lat: latitude
            lon: longitude
            timezone: timeZone
          }
          scheduledArrivalTime: aimedArrivalTime
          expectedArrivalTime: actualArrivalTime
          scheduledDepartureTime: aimedDepartureTime
          expectedDepartureTime: actualDepartureTime
          occupancyStatus
        }
        legGeometry: pointsOnLink @include(if: $withPaths) {
          length
          points
        }
        steps @include(if: $withPaths) {
            lat: latitude
            lon: longitude
            legStepText: streetName
        }
        occupancy: fromEstimatedCall { occupancyStatus }
      }
    }
  }
}

fragment locationFragment on Place {
    name
    lat: latitude
    lon: longitude
    stop: quay {
        platformCode: publicCode
        id
        timezone: timeZone
    }
    bikeRentalStation {
        id
        networks,
        bikesAvailable
    }
}

fragment estimatedCallFragment on EstimatedCall {
    forBoarding
    forAlighting
    requestStop
    cancellation
}
