{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://postflight.co/aeronautiql/planning/v1/results/trajectory-result-v1.schema.json",
  "title": "Existing Rust FlightWindsResult v1 passthrough",
  "description": "Core compatibility schema for trajectory::contract::FlightWindsResult. Property names intentionally remain snake_case.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version", "evaluator_revision", "trajectory_id", "schedule_id",
    "aircraft_id", "performance_revision", "etd_unix", "wind_source",
    "forecast", "units", "totals", "top_of_climb", "top_of_descent",
    "phases", "samples", "quality_flags", "schedule_quality",
    "schedule_quality_notes", "solver", "terminal_forecasts"
  ],
  "properties": {
    "schema_version": { "const": 1 },
    "evaluator_revision": { "type": "string", "minLength": 1 },
    "trajectory_id": { "type": "string", "minLength": 1 },
    "schedule_id": { "type": "string", "minLength": 1 },
    "aircraft_id": { "type": "string", "minLength": 1 },
    "performance_revision": { "type": "string", "minLength": 1 },
    "etd_unix": { "type": "number" },
    "wind_source": { "enum": ["forecast", "manual"] },
    "forecast": {
      "oneOf": [
        { "type": "null" },
        { "$ref": "#/$defs/forecast" }
      ]
    },
    "units": { "$ref": "#/$defs/units" },
    "totals": { "$ref": "#/$defs/totals" },
    "top_of_climb": { "$ref": "#/$defs/point" },
    "top_of_descent": { "$ref": "#/$defs/point" },
    "phases": { "type": "array", "maxItems": 1000, "items": { "$ref": "#/$defs/phase" } },
    "samples": { "type": "array", "maxItems": 20000, "items": { "$ref": "#/$defs/sample" } },
    "quality_flags": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/qualityFlag" } },
    "schedule_quality": { "enum": ["supported", "owner_estimate"] },
    "schedule_quality_notes": { "type": "array", "items": { "type": "string" } },
    "solver": { "$ref": "#/$defs/solver" },
    "terminal_forecasts": { "type": "array", "items": { "$ref": "#/$defs/terminalForecast" } },
    "route_legs": {
      "type": ["array", "null"],
      "items": { "$ref": "#/$defs/routeLeg" }
    },
    "planning_weather": {
      "description": "Revision-6 additive provenance. Shape remains producer-owned until its native contract is frozen.",
      "type": ["object", "null"]
    }
  },
  "$defs": {
    "point": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lat", "lon", "distance_nm", "elapsed_seconds", "utc_unix", "pressure_altitude_ft"],
      "properties": {
        "lat": { "type": "number", "minimum": -90, "maximum": 90 },
        "lon": { "type": "number", "minimum": -180, "maximum": 180 },
        "distance_nm": { "type": "number", "minimum": 0 },
        "elapsed_seconds": { "type": "number", "minimum": 0 },
        "utc_unix": { "type": "number" },
        "pressure_altitude_ft": { "type": "number" }
      }
    },
    "fuel": {
      "type": "object",
      "additionalProperties": false,
      "required": ["unit", "value"],
      "properties": {
        "unit": { "enum": ["pounds", "kilograms", "gallons", "liters"] },
        "value": { "type": "number", "minimum": 0 }
      }
    },
    "forecast": {
      "type": "object",
      "additionalProperties": false,
      "required": ["cycle", "valid_from_unix", "valid_through_unix"],
      "properties": {
        "cycle": { "type": "string", "minLength": 1 },
        "valid_from_unix": { "type": "number" },
        "valid_through_unix": { "type": "number" }
      }
    },
    "units": {
      "type": "object",
      "additionalProperties": false,
      "required": ["distance", "speed", "wind_components", "altitude", "temperature", "time", "headwind_sign", "crosswind_sign", "wind_direction"],
      "properties": {
        "distance": { "const": "nm" },
        "speed": { "const": "kt" },
        "wind_components": { "const": "m/s" },
        "altitude": { "const": "pressure_altitude_ft" },
        "temperature": { "const": "celsius" },
        "time": { "const": "seconds" },
        "headwind_sign": { "const": "positive_opposing_true_course" },
        "crosswind_sign": { "const": "positive_from_right" },
        "wind_direction": { "const": "from_degrees_true" }
      }
    },
    "totals": {
      "type": "object",
      "additionalProperties": false,
      "required": ["ete_seconds", "physical_ete_seconds", "allowance_seconds", "cruise_seconds", "physical_distance_nm", "allowance_distance_nm", "arrival_unix", "average_physical_headwind_kt", "average_crosswind_kt", "average_crab_loss_kt", "average_temperature_c", "fuel"],
      "properties": {
        "ete_seconds": { "type": "number", "minimum": 0 },
        "physical_ete_seconds": { "type": "number", "minimum": 0 },
        "allowance_seconds": { "type": "number", "minimum": 0 },
        "cruise_seconds": { "type": "number", "minimum": 0 },
        "physical_distance_nm": { "type": "number", "minimum": 0 },
        "allowance_distance_nm": { "type": "number", "minimum": 0 },
        "arrival_unix": { "type": "number" },
        "average_physical_headwind_kt": { "type": "number" },
        "average_crosswind_kt": { "type": "number" },
        "average_crab_loss_kt": { "type": "number" },
        "average_temperature_c": { "type": "number" },
        "fuel": { "oneOf": [{ "type": "null" }, { "$ref": "#/$defs/fuel" }] }
      }
    },
    "phase": {
      "type": "object",
      "additionalProperties": false,
      "required": ["phase_index", "phase_id", "kind", "track", "start", "end", "duration_seconds", "distance_nm", "sample_count", "average_physical_headwind_kt", "average_crosswind_kt", "average_crab_loss_kt", "average_temperature_c", "fuel"],
      "properties": {
        "phase_index": { "type": "integer", "minimum": 0 },
        "phase_id": { "type": "string", "minLength": 1 },
        "kind": { "$ref": "#/$defs/phaseKind" },
        "track": { "enum": ["route", "allowance"] },
        "start": { "$ref": "#/$defs/point" },
        "end": { "$ref": "#/$defs/point" },
        "duration_seconds": { "type": "number", "minimum": 0 },
        "distance_nm": { "type": "number", "minimum": 0 },
        "sample_count": { "type": "integer", "minimum": 0 },
        "average_physical_headwind_kt": { "type": ["number", "null"] },
        "average_crosswind_kt": { "type": ["number", "null"] },
        "average_crab_loss_kt": { "type": ["number", "null"] },
        "average_temperature_c": { "type": ["number", "null"] },
        "fuel": { "oneOf": [{ "type": "null" }, { "$ref": "#/$defs/fuel" }] }
      }
    },
    "sample": {
      "type": "object",
      "additionalProperties": false,
      "required": ["sample_index", "sample_id", "phase_index", "phase_id", "phase_kind", "track", "start", "end", "weather_point", "scheduled_speed", "cas_kt", "tas_kt", "mach", "horizontal_tas_kt", "vertical_speed_fpm", "groundspeed_kt", "true_course_deg", "corrected_heading_deg", "wind_east_ms", "wind_north_ms", "wind_from_deg", "wind_speed_kt", "physical_headwind_kt", "crosswind_kt", "crab_loss_kt", "temperature_c", "isa_deviation_c", "static_pressure_hpa", "interval_seconds", "interval_distance_nm", "fuel", "quality_flags", "weather_source"],
      "properties": {
        "sample_index": { "type": "integer", "minimum": 0 },
        "sample_id": { "type": "string", "minLength": 1 },
        "phase_index": { "type": "integer", "minimum": 0 },
        "phase_id": { "type": "string", "minLength": 1 },
        "phase_kind": { "$ref": "#/$defs/phaseKind" },
        "track": { "enum": ["route", "allowance"] },
        "start": { "$ref": "#/$defs/point" },
        "end": { "$ref": "#/$defs/point" },
        "weather_point": { "$ref": "#/$defs/point" },
        "scheduled_speed": { "$ref": "#/$defs/scheduledSpeed" },
        "cas_kt": { "type": "number" },
        "tas_kt": { "type": "number" },
        "mach": { "type": "number" },
        "horizontal_tas_kt": { "type": "number" },
        "vertical_speed_fpm": { "type": "number" },
        "groundspeed_kt": { "type": "number" },
        "true_course_deg": { "type": "number" },
        "corrected_heading_deg": { "type": "number" },
        "wind_east_ms": { "type": "number" },
        "wind_north_ms": { "type": "number" },
        "wind_from_deg": { "type": "number" },
        "wind_speed_kt": { "type": "number", "minimum": 0 },
        "physical_headwind_kt": { "type": "number" },
        "crosswind_kt": { "type": "number" },
        "crab_loss_kt": { "type": "number" },
        "temperature_c": { "type": "number" },
        "isa_deviation_c": { "type": "number" },
        "static_pressure_hpa": { "type": "number", "exclusiveMinimum": 0 },
        "interval_seconds": { "type": "number", "minimum": 0 },
        "interval_distance_nm": { "type": "number", "minimum": 0 },
        "fuel": { "type": ["number", "null"] },
        "mass": { "$ref": "#/$defs/mass" },
        "quality_flags": { "type": "array", "items": { "$ref": "#/$defs/qualityFlag" } },
        "weather_source": { "oneOf": [{ "type": "null" }, { "$ref": "#/$defs/weatherSource" }] }
      }
    },
    "scheduledSpeed": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "value"],
      "properties": {
        "kind": { "enum": ["ias", "cas", "mach", "tas"] },
        "value": { "type": "number", "exclusiveMinimum": 0 }
      }
    },
    "mass": {
      "type": "object",
      "additionalProperties": false,
      "required": ["start_weight_lb", "end_weight_lb", "cumulative_fuel_burn_lb"],
      "properties": {
        "start_weight_lb": { "type": "number", "minimum": 0 },
        "end_weight_lb": { "type": "number", "minimum": 0 },
        "cumulative_fuel_burn_lb": { "type": "number", "minimum": 0 }
      }
    },
    "weatherSource": {
      "type": "object",
      "additionalProperties": true,
      "required": ["model", "cycle"],
      "properties": {
        "model": { "enum": ["gfs", "hrrr", "climatology", "standard_atmosphere"] },
        "cycle": { "type": "string", "minLength": 1 },
        "terminal_id": { "type": "string", "minLength": 1 }
      }
    },
    "terminalForecast": {
      "type": "object",
      "additionalProperties": false,
      "required": ["model", "terminal_id", "cycle", "valid_from_unix", "valid_through_unix", "lat", "lon", "coverage_radius_nm", "handoff_pressure_hpa", "engaged", "disengaged_reason"],
      "properties": {
        "model": { "enum": ["gfs", "hrrr", "climatology", "standard_atmosphere"] },
        "terminal_id": { "type": "string", "minLength": 1 },
        "cycle": { "type": "string", "minLength": 1 },
        "valid_from_unix": { "type": "number" },
        "valid_through_unix": { "type": "number" },
        "lat": { "type": "number", "minimum": -90, "maximum": 90 },
        "lon": { "type": "number", "minimum": -180, "maximum": 180 },
        "coverage_radius_nm": { "type": "number", "minimum": 0 },
        "handoff_pressure_hpa": { "type": "number", "exclusiveMinimum": 0 },
        "engaged": { "type": "boolean" },
        "disengaged_reason": { "type": ["string", "null"] }
      }
    },
    "routeLeg": {
      "type": "object",
      "additionalProperties": false,
      "required": ["index", "distance_nm", "seconds", "elapsed_seconds", "pressure_altitude_ft"],
      "properties": {
        "index": { "type": "integer", "minimum": 1 },
        "from_id": { "type": "string" },
        "to_id": { "type": "string" },
        "distance_nm": { "type": "number", "minimum": 0 },
        "seconds": { "type": "number", "minimum": 0 },
        "elapsed_seconds": { "type": "number", "minimum": 0 },
        "pressure_altitude_ft": { "type": "number" },
        "fuel": { "$ref": "#/$defs/fuel" }
      }
    },
    "solver": {
      "type": "object",
      "additionalProperties": false,
      "required": ["cruise_iterations", "endpoint_error_nm", "forecast_queries", "steps", "corrector_iterations_max"],
      "properties": {
        "cruise_iterations": { "type": "integer", "minimum": 0 },
        "endpoint_error_nm": { "type": "number", "minimum": 0 },
        "forecast_queries": { "type": "integer", "minimum": 0 },
        "steps": { "type": "integer", "minimum": 0 },
        "corrector_iterations_max": { "type": "integer", "minimum": 0 }
      }
    },
    "phaseKind": {
      "enum": ["departure_allowance", "climb", "accelerate", "cruise", "decelerate", "descend", "arrival_allowance"]
    },
    "qualityFlag": {
      "enum": ["ias_equals_cas", "speed_transition", "manual_wind", "isa_temperature", "estimated_terminal_allowance", "near_surface_blend", "surface_reference", "terrain_adjusted_surface_reference", "owner_estimate_schedule", "refined_step", "climatology_estimate", "standard_atmosphere_estimate"]
    }
  }
}
