{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://postflight.co/aeronautiql/planning/v1_1/results/planning-snapshot.schema.json",
  "title": "Shared planning immutable snapshot v1.1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "snapshotId",
    "documentId",
    "commitId",
    "generation",
    "publishedAt",
    "planState",
    "publication",
    "engineResults",
    "legs",
    "tripMetrics",
    "issues"
  ],
  "properties": {
    "schemaVersion": {
      "const": "1.1"
    },
    "snapshotId": {
      "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/properties/snapshotId"
    },
    "documentId": {
      "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/properties/documentId"
    },
    "commitId": {
      "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/properties/commitId"
    },
    "generation": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "publishedAt": {
      "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/properties/publishedAt"
    },
    "planState": {
      "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/properties/planState"
    },
    "publication": {
      "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/properties/publication"
    },
    "engineResults": {
      "type": "array",
      "maxItems": 2000,
      "items": {
        "$ref": "engine-result.schema.json"
      }
    },
    "legs": {
      "type": "array",
      "maxItems": 1000,
      "items": {
        "$ref": "#/$defs/leg"
      }
    },
    "tripMetrics": {
      "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/properties/tripMetrics"
    },
    "issues": {
      "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/properties/issues"
    },
    "extensions": {
      "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/properties/extensions"
    },
    "reuseSources": {
      "type": "array",
      "maxItems": 2000,
      "items": {
        "$ref": "https://postflight.co/aeronautiql/planning/v1_1/results/cache-reuse.schema.json#/$defs/source"
      }
    }
  },
  "$defs": {
    "leg": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "legId",
        "ordinal",
        "dependencyKey",
        "resolution",
        "evaluation",
        "vertical",
        "metrics"
      ],
      "properties": {
        "legId": {
          "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/$defs/leg/properties/legId"
        },
        "ordinal": {
          "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/$defs/leg/properties/ordinal"
        },
        "dependencyKey": {
          "$ref": "engine-result.schema.json#/properties/dependencyKey"
        },
        "resolution": {
          "$ref": "#/$defs/componentBinding"
        },
        "evaluation": {
          "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/$defs/leg/properties/evaluation"
        },
        "vertical": {
          "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/$defs/leg/properties/vertical"
        },
        "metrics": {
          "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/$defs/leg/properties/metrics"
        }
      }
    },
    "componentBinding": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "state"
      ],
      "properties": {
        "state": {
          "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/$defs/componentBinding/properties/state"
        },
        "resultId": {
          "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/$defs/componentBinding/properties/resultId"
        },
        "routeIdentity": {
          "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/$defs/componentBinding/properties/routeIdentity"
        },
        "resolutionMappingId": {
          "$ref": "https://postflight.co/aeronautiql/planning/v1/results/planning-snapshot.schema.json#/$defs/componentBinding/properties/mappingId"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "state": {
                "const": "usable"
              }
            }
          },
          "then": {
            "required": [
              "resultId",
              "routeIdentity"
            ]
          }
        }
      ]
    }
  }
}
