{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://developer.sabre.com/schemas/itinerary",
  "title": "Sabre Itinerary",
  "description": "A priced air itinerary returned from Sabre Bargain Finder Max or re-shop operations",
  "type": "object",
  "properties": {
    "sequenceNumber": {
      "type": "integer",
      "description": "Ranking position in shopping response",
      "minimum": 1
    },
    "airItinerary": {
      "type": "object",
      "description": "Flight segments composing the itinerary",
      "properties": {
        "directionInd": {
          "type": "string",
          "enum": ["OneWay", "Return", "OpenJaw", "Circle"],
          "description": "Itinerary direction type"
        },
        "originDestinationOptions": {
          "type": "array",
          "description": "Each leg of the journey",
          "items": {
            "type": "object",
            "properties": {
              "flightSegments": {
                "type": "array",
                "items": {
                  "$ref": "#/$defs/FlightSegment"
                }
              },
              "elapsedTime": {
                "type": "integer",
                "description": "Total leg duration in minutes"
              },
              "stops": {
                "type": "integer",
                "minimum": 0,
                "description": "Number of stops in this leg"
              }
            }
          }
        }
      },
      "required": ["directionInd", "originDestinationOptions"]
    },
    "pricingInfo": {
      "$ref": "#/$defs/PricingInfo"
    },
    "validatingCarrier": {
      "type": "string",
      "description": "IATA code of the carrier validating the ticket",
      "pattern": "^[A-Z0-9]{2}$"
    },
    "ticketingRequirements": {
      "type": "object",
      "properties": {
        "ticketType": {
          "type": "string",
          "enum": ["eTicket", "Paper"]
        },
        "lastTicketingDate": {
          "type": "string",
          "format": "date"
        }
      }
    }
  },
  "required": ["sequenceNumber", "airItinerary", "pricingInfo"],
  "$defs": {
    "FlightSegment": {
      "type": "object",
      "description": "A single flight segment (one takeoff and landing)",
      "properties": {
        "departureAirport": {
          "type": "string",
          "pattern": "^[A-Z]{3}$",
          "description": "IATA departure airport code"
        },
        "arrivalAirport": {
          "type": "string",
          "pattern": "^[A-Z]{3}$",
          "description": "IATA arrival airport code"
        },
        "departureDateTime": {
          "type": "string",
          "format": "date-time"
        },
        "arrivalDateTime": {
          "type": "string",
          "format": "date-time"
        },
        "marketingAirline": {
          "type": "string",
          "pattern": "^[A-Z0-9]{2}$",
          "description": "IATA code of marketing carrier"
        },
        "operatingAirline": {
          "type": "string",
          "pattern": "^[A-Z0-9]{2}$",
          "description": "IATA code of operating carrier"
        },
        "flightNumber": {
          "type": "string",
          "example": "AA100"
        },
        "bookingClass": {
          "type": "string",
          "description": "Reservation booking designator (RBD)",
          "pattern": "^[A-Z]$"
        },
        "cabinClass": {
          "type": "string",
          "enum": ["Y", "W", "C", "F"],
          "description": "Y=Economy, W=PremiumEconomy, C=Business, F=First"
        },
        "equipment": {
          "type": "string",
          "description": "IATA aircraft equipment type code",
          "example": "789"
        },
        "elapsedTime": {
          "type": "integer",
          "description": "Segment duration in minutes"
        },
        "stopQuantity": {
          "type": "integer",
          "minimum": 0
        },
        "fareBasis": {
          "type": "string",
          "description": "Fare basis code for this segment"
        }
      },
      "required": [
        "departureAirport",
        "arrivalAirport",
        "departureDateTime",
        "arrivalDateTime",
        "marketingAirline",
        "flightNumber",
        "bookingClass"
      ]
    },
    "PricingInfo": {
      "type": "object",
      "description": "Total pricing breakdown for the itinerary",
      "properties": {
        "baseFare": {
          "$ref": "#/$defs/MonetaryAmount"
        },
        "totalTaxes": {
          "$ref": "#/$defs/MonetaryAmount"
        },
        "totalFare": {
          "$ref": "#/$defs/MonetaryAmount"
        },
        "taxes": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "taxCode": {
                "type": "string",
                "description": "IATA tax code (e.g., US, YQ, YR)"
              },
              "amount": {
                "$ref": "#/$defs/MonetaryAmount"
              },
              "description": {
                "type": "string"
              }
            },
            "required": ["taxCode", "amount"]
          }
        },
        "passengerTypeBreakdown": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "passengerType": {
                "type": "string",
                "enum": ["ADT", "CHD", "INF", "INS"]
              },
              "quantity": {
                "type": "integer"
              },
              "perPassengerFare": {
                "$ref": "#/$defs/MonetaryAmount"
              }
            }
          }
        }
      },
      "required": ["baseFare", "totalFare"]
    },
    "MonetaryAmount": {
      "type": "object",
      "properties": {
        "amount": {
          "type": "number",
          "minimum": 0
        },
        "currencyCode": {
          "type": "string",
          "pattern": "^[A-Z]{3}$",
          "description": "ISO 4217 currency code"
        }
      },
      "required": ["amount", "currencyCode"]
    }
  }
}
