# 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 }
        line {
          presentation {
            color: colour
            textColor: textColour
          }
          transportMode
          type: transportSubmode
          shortName: publicCode
          name
          bikesAllowed
          agency: operator {
            name
          }
          alerts: situations {
            alertHeaderTextTranslations: summary {
                language
                text: value
            }
            alertDescriptionTextTranslations: description {
                language
                text: value
            }
          }
        }
        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
        }
        legGeometry: pointsOnLink @include(if: $withPaths) {
          length
          points
        }
        steps @include(if: $withPaths) {
            lat: latitude
            lon: longitude
            legStepText: streetName
        }
      }
    }
  }
}

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