{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://postflight.co/aeronautiql/planning/v1/intent/intent.schema.json",
  "title": "Aeronautiql planning intent document v1",
  "description": "Portable editable plan intent. Every plan input is optional so empty, origin-only and partial drafts are representable; evaluation eligibility is a separate rule. Derived engine and display products are excluded.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "documentId", "commitId", "stops", "legs", "importAssessment"],
  "properties": {
    "schemaVersion": { "const": "1.0" },
    "documentId": { "$ref": "#/$defs/id" },
    "commitId": { "$ref": "#/$defs/id" },
    "stops": {
      "type": "array",
      "maxItems": 128,
      "items": { "$ref": "#/$defs/stop" }
    },
    "legs": {
      "type": "array",
      "maxItems": 64,
      "items": { "$ref": "#/$defs/leg" }
    },
    "aircraft": { "$ref": "#/$defs/aircraftInput" },
    "schedule": { "$ref": "#/$defs/scheduleInput" },
    "stopPlanning": { "$ref": "#/$defs/stopPlanningInput" },
    "importAssessment": { "$ref": "#/$defs/importAssessment" },
    "extensions": { "$ref": "#/$defs/extensions" }
  },
  "$defs": {
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:>@/-]*$"
    },
    "ident": {
      "type": "string",
      "minLength": 1,
      "maxLength": 32,
      "pattern": "^[A-Z0-9][A-Z0-9._-]*$"
    },
    "utc": {
      "description": "RFC 3339 UTC instant: uppercase T and Z, no offset, at most millisecond precision.",
      "type": "string",
      "format": "date-time",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{1,3})?Z$"
    },
    "finiteNumber": { "type": "number" },
    "nonNegativeNumber": { "type": "number", "minimum": 0 },
    "positiveNumber": { "type": "number", "exclusiveMinimum": 0 },
    "coordinate": {
      "type": "object",
      "additionalProperties": false,
      "required": ["latitudeDeg", "longitudeDeg", "datum"],
      "properties": {
        "latitudeDeg": { "type": "number", "minimum": -90, "maximum": 90 },
        "longitudeDeg": { "type": "number", "minimum": -180, "maximum": 180 },
        "datum": { "const": "WGS84" }
      }
    },
    "extensions": {
      "type": "object",
      "maxProperties": 64,
      "propertyNames": {
        "pattern": "^[a-z][a-z0-9]*(\\.[a-z0-9][a-z0-9-]*)+$"
      }
    },
    "stop": {
      "type": "object",
      "additionalProperties": false,
      "required": ["stopId", "kind"],
      "properties": {
        "stopId": { "$ref": "#/$defs/id" },
        "kind": { "enum": ["airport", "waypoint", "coordinate", "address"] },
        "ident": { "$ref": "#/$defs/ident" },
        "coordinate": { "$ref": "#/$defs/coordinate" },
        "label": { "type": "string", "minLength": 1, "maxLength": 256 },
        "extensions": { "$ref": "#/$defs/extensions" }
      },
      "allOf": [
        {
          "if": { "properties": { "kind": { "enum": ["airport", "waypoint"] } }, "required": ["kind"] },
          "then": { "required": ["ident"] }
        },
        {
          "if": { "properties": { "kind": { "enum": ["coordinate", "address"] } }, "required": ["kind"] },
          "then": { "required": ["coordinate"] }
        }
      ]
    },
    "leg": {
      "type": "object",
      "additionalProperties": false,
      "required": ["legId", "originStopId", "destinationStopId", "elements"],
      "properties": {
        "legId": { "$ref": "#/$defs/id" },
        "originStopId": { "$ref": "#/$defs/id" },
        "destinationStopId": { "$ref": "#/$defs/id" },
        "elements": {
          "description": "Ordered route intent. Empty means the pair is entered but no route has been chosen yet.",
          "type": "array",
          "maxItems": 1024,
          "items": { "$ref": "#/$defs/routeElement" }
        },
        "schedule": { "$ref": "#/$defs/legScheduleInput" },
        "tablePerformanceInput": { "$ref": "#/$defs/tablePerformanceLegInput" },
        "extensions": { "$ref": "#/$defs/extensions" }
      }
    },
    "routeElement": {
      "type": "object",
      "additionalProperties": false,
      "required": ["elementId", "kind"],
      "properties": {
        "elementId": { "$ref": "#/$defs/id" },
        "kind": {
          "enum": ["fix", "airway", "procedure", "direct", "discontinuity", "coordinate", "userWaypoint"]
        },
        "ident": { "$ref": "#/$defs/ident" },
        "coordinate": { "$ref": "#/$defs/coordinate" },
        "procedureRole": { "enum": ["departure", "arrival", "approach"] },
        "runway": {
          "description": "Pilot-selected runway for a procedure, for example RW16R. Never inferred from a resolver result.",
          "type": "string",
          "pattern": "^RW[0-9]{2}[LCR]?$"
        },
        "transition": { "$ref": "#/$defs/ident" },
        "entryElementId": { "$ref": "#/$defs/id" },
        "exitElementId": { "$ref": "#/$defs/id" },
        "altitudeConstraint": { "$ref": "#/$defs/altitudeConstraint" },
        "extensions": { "$ref": "#/$defs/extensions" }
      },
      "allOf": [
        {
          "if": { "properties": { "kind": { "enum": ["fix", "airway", "procedure", "userWaypoint"] } }, "required": ["kind"] },
          "then": { "required": ["ident"] }
        },
        {
          "if": { "properties": { "kind": { "const": "coordinate" } }, "required": ["kind"] },
          "then": { "required": ["coordinate"] }
        },
        {
          "if": { "properties": { "kind": { "const": "procedure" } }, "required": ["kind"] },
          "then": { "required": ["procedureRole"] }
        }
      ]
    },
    "altitude": {
      "type": "object",
      "additionalProperties": false,
      "required": ["value", "unit", "datum"],
      "properties": {
        "value": { "$ref": "#/$defs/finiteNumber" },
        "unit": { "enum": ["ft", "m"] },
        "datum": { "enum": ["pressureAltitude", "geometricMsl", "heightAgl"] }
      }
    },
    "pressureAltitude": {
      "type": "object",
      "additionalProperties": false,
      "required": ["value", "unit", "datum"],
      "properties": {
        "value": { "$ref": "#/$defs/positiveNumber" },
        "unit": { "enum": ["ft", "m"] },
        "datum": { "const": "pressureAltitude" }
      }
    },
    "altitudeInterval": {
      "type": "object",
      "additionalProperties": false,
      "required": ["value", "unit"],
      "properties": {
        "value": { "$ref": "#/$defs/positiveNumber" },
        "unit": { "enum": ["ft", "m"] }
      }
    },
    "altitudeConstraint": {
      "type": "object",
      "additionalProperties": false,
      "minProperties": 1,
      "properties": {
        "at": { "$ref": "#/$defs/altitude" },
        "minimum": { "$ref": "#/$defs/altitude" },
        "maximum": { "$ref": "#/$defs/altitude" }
      }
    },
    "speed": {
      "type": "object",
      "additionalProperties": false,
      "required": ["value", "unit"],
      "properties": {
        "value": { "$ref": "#/$defs/positiveNumber" },
        "unit": { "const": "kt" }
      }
    },
    "fuelUnit": { "enum": ["lb", "usGal", "kg", "l"] },
    "fuelQuantity": {
      "type": "object",
      "additionalProperties": false,
      "required": ["value", "unit"],
      "properties": {
        "value": { "$ref": "#/$defs/nonNegativeNumber" },
        "unit": { "$ref": "#/$defs/fuelUnit" }
      }
    },
    "weight": {
      "type": "object",
      "additionalProperties": false,
      "required": ["value", "unit"],
      "properties": {
        "value": { "$ref": "#/$defs/positiveNumber" },
        "unit": { "enum": ["lb", "kg"] }
      }
    },
    "aircraftInput": {
      "description": "Every member is optional. An absent member was not entered and MUST NOT be defaulted by an importer.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "aircraftId": { "$ref": "#/$defs/id" },
        "aircraftType": { "type": "string", "minLength": 1, "maxLength": 64 },
        "performanceProfileId": { "$ref": "#/$defs/id" },
        "cruiseSpeed": { "$ref": "#/$defs/speed" },
        "selectedSpeedPreset": { "$ref": "#/$defs/speed" },
        "cruiseAltitude": { "$ref": "#/$defs/altitude" },
        "altitudeMode": { "enum": ["manual", "automatic"] },
        "altitudeSearch": { "$ref": "#/$defs/altitudeSearch" },
        "manualWind": { "$ref": "#/$defs/windInput" },
        "fuel": { "$ref": "#/$defs/fuelInput" },
        "tablePerformanceSelection": { "$ref": "#/$defs/versionedNativeInput" },
        "extensions": { "$ref": "#/$defs/extensions" }
      },
      "allOf": [
        {
          "if": { "properties": { "altitudeMode": { "const": "automatic" } }, "required": ["altitudeMode"] },
          "then": { "required": ["altitudeSearch"] }
        }
      ]
    },
    "altitudeSearch": {
      "description": "Native automatic-altitude search input. Floor, course and atmosphere are derived per leg by the engine.",
      "type": "object",
      "additionalProperties": false,
      "required": ["ceiling", "step", "hemisphericRule", "minimumCruiseSeconds", "preferenceToleranceSeconds"],
      "properties": {
        "ceiling": { "$ref": "#/$defs/pressureAltitude" },
        "step": { "$ref": "#/$defs/altitudeInterval" },
        "hemisphericRule": { "enum": ["ifr", "vfr", "none"] },
        "minimumCruiseSeconds": { "$ref": "#/$defs/nonNegativeNumber" },
        "preferenceToleranceSeconds": { "$ref": "#/$defs/nonNegativeNumber" }
      }
    },
    "windInput": {
      "type": "object",
      "additionalProperties": false,
      "required": ["componentKt", "signConvention", "ownership"],
      "properties": {
        "componentKt": { "$ref": "#/$defs/finiteNumber" },
        "signConvention": {
          "description": "Positive is a tailwind: ground speed = true airspeed + componentKt.",
          "const": "tailwindPositive"
        },
        "ownership": { "const": "pilot" }
      }
    },
    "fuelInput": {
      "type": "object",
      "additionalProperties": false,
      "required": ["unit"],
      "properties": {
        "unit": { "$ref": "#/$defs/fuelUnit" },
        "burnPerHour": { "$ref": "#/$defs/nonNegativeNumber" },
        "capacity": { "$ref": "#/$defs/nonNegativeNumber" }
      }
    },
    "versionedNativeInput": {
      "description": "Source-owned selection carried as a versioned value. A consumer that does not support the version reports the import unsupported.",
      "type": "object",
      "additionalProperties": false,
      "required": ["format", "version", "value"],
      "properties": {
        "format": { "type": "string", "pattern": "^[a-z][a-z0-9]*(\\.[a-z0-9][a-zA-Z0-9-]*)+$" },
        "version": { "type": "integer", "minimum": 1 },
        "value": { "type": "object", "maxProperties": 64 }
      }
    },
    "tablePerformanceLegInput": {
      "description": "Source-backed per-leg table input: explicit departure weight and optional leg fuel budget and reserve.",
      "type": "object",
      "additionalProperties": false,
      "required": ["departureWeight", "departureWeightSource"],
      "properties": {
        "departureWeight": { "$ref": "#/$defs/weight" },
        "departureWeightSource": { "enum": ["entered", "assumedMaximum"] },
        "usableFuel": { "$ref": "#/$defs/fuelQuantity" },
        "reserveFuel": { "$ref": "#/$defs/fuelQuantity" }
      }
    },
    "scheduleInput": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "plannedDepartureUtc": {
          "description": "Trip departure clock for a source without per-leg schedules. When the first leg also has one they MUST be equal.",
          "$ref": "#/$defs/utc"
        },
        "taxiOutMinutes":{ "type": "integer", "minimum": 0, "maximum": 1440 },
        "taxiInMinutes": { "type": "integer", "minimum": 0, "maximum": 1440 },
        "stopDurationMinutes": { "type": "integer", "minimum": 0, "maximum": 10080 },
        "dispatchTripId": { "$ref": "#/$defs/id" },
        "extensions": { "$ref": "#/$defs/extensions" }
      }
    },
    "legScheduleInput": {
      "description": "Pilot-entered clock for one leg. In automatic timing the engine owns arrival and duration, so only the departure is intent.",
      "type": "object",
      "additionalProperties": false,
      "required": ["timingMode"],
      "properties": {
        "timingMode": { "enum": ["manual", "automatic"] },
        "plannedDepartureUtc": { "$ref": "#/$defs/utc" },
        "plannedArrivalUtc": { "$ref": "#/$defs/utc" },
        "plannedDurationMinutes": { "type": "integer", "minimum": 1, "maximum": 10080 }
      }
    },
    "stopPlanningInput": {
      "description": "Stop-search preferences. Every member is optional; the stop engine applies its own documented default for an absent member.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "maxStops": { "type": "integer", "minimum": 0, "maximum": 32 },
        "maxItineraries": { "type": "integer", "minimum": 1, "maximum": 100 },
        "maxLegNm": { "$ref": "#/$defs/positiveNumber" },
        "viaText": { "type": "string", "maxLength": 4096 },
        "useMaxLegDirectly": { "type": "boolean" },
        "includeSpecialUse": { "type": "boolean" },
        "optimize": { "enum": ["distance", "time", "fuel"] },
        "reserveFuel": {
          "description": "Fuel quantity the stop planner must keep on arrival. Never a percentage.",
          "$ref": "#/$defs/fuelQuantity"
        },
        "rangeFactor": { "type": "number", "exclusiveMinimum": 0, "maximum": 1 },
        "airportFilters": { "$ref": "#/$defs/airportFilters" },
        "extensions": { "$ref": "#/$defs/extensions" }
      }
    },
    "airportFilters": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "publicOnly": { "type": "boolean" },
        "fuelOnly": { "type": "boolean" },
        "minimumRunwayFt": { "type": "integer", "minimum": 0, "maximum": 30000 },
        "requiresIap": { "type": "boolean" },
        "fuelProviderKeys": {
          "type": "array",
          "maxItems": 128,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1, "maxLength": 64 }
        }
      }
    },
    "importAssessment": {
      "type": "object",
      "additionalProperties": false,
      "required": ["sourceFormat", "outcome", "issues"],
      "properties": {
        "sourceFormat": { "enum": ["intent-v1", "native-trip-codable", "route-text"] },
        "outcome": { "enum": ["lossless", "lossy", "unsupported"] },
        "issues": {
          "type": "array",
          "maxItems": 256,
          "items": { "$ref": "#/$defs/importIssue" }
        }
      }
    },
    "importIssue": {
      "type": "object",
      "additionalProperties": false,
      "required": ["code", "path", "detail"],
      "properties": {
        "code": {
          "enum": [
            "identitySynthesized",
            "routeTextAmbiguous",
            "unknownRequiredSemantic",
            "unsupportedVersion",
            "nativeCodecDropsUnknownField",
            "derivedFieldExcluded",
            "legacyAliasNormalized",
            "nativeDecodeDefault",
            "nativeValueUnparseable",
            "timePrecisionReduced"
          ]
        },
        "path": { "type": "string", "minLength": 1, "maxLength": 512 },
        "detail": { "type": "string", "minLength": 1, "maxLength": 2048 }
      }
    }
  }
}
