{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json",
  "title": "Shared planning result common values v1",
  "$defs": {
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 256
    },
    "sha256": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "utc": {
      "type": "string",
      "format": "date-time",
      "description": "RFC 3339 UTC profile: uppercase T and Z, at most millisecond precision, compared as integer milliseconds.",
      "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$"
    },
    "coordinate": {
      "type": "array",
      "description": "WGS84 longitude, latitude order; never latitude, longitude.",
      "prefixItems": [
        {
          "type": "number",
          "minimum": -180,
          "maximum": 180
        },
        {
          "type": "number",
          "minimum": -90,
          "maximum": 90
        }
      ],
      "minItems": 2,
      "maxItems": 2
    },
    "dependencyKey": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "keyId",
        "documentId",
        "commitId",
        "legId",
        "routeIntentId",
        "aircraftId",
        "scheduleId",
        "plannedDepartureUtc",
        "navigationRevision",
        "weatherRevision",
        "performanceRevision",
        "policyRevision"
      ],
      "properties": {
        "keyId": {
          "$ref": "#/$defs/sha256"
        },
        "documentId": {
          "$ref": "#/$defs/intentId"
        },
        "commitId": {
          "$ref": "#/$defs/intentId"
        },
        "legId": {
          "$ref": "#/$defs/intentId"
        },
        "routeIntentId": {
          "$ref": "#/$defs/id"
        },
        "aircraftId": {
          "$ref": "#/$defs/id"
        },
        "scheduleId": {
          "$ref": "#/$defs/id"
        },
        "plannedDepartureUtc": {
          "$ref": "#/$defs/utc"
        },
        "navigationRevision": {
          "$ref": "#/$defs/id"
        },
        "weatherRevision": {
          "description": "Null only while weather-dependent evaluation is pending or unavailable.",
          "type": [
            "string",
            "null"
          ],
          "minLength": 1,
          "maxLength": 256
        },
        "performanceRevision": {
          "$ref": "#/$defs/id"
        },
        "policyRevision": {
          "$ref": "#/$defs/id"
        },
        "additionalDataRevisions": {
          "description": "Every other consumed dataset, for example terrain or airport elevation. Omit only when no additional dataset was used.",
          "type": "object",
          "minProperties": 1,
          "propertyNames": {
            "pattern": "^[a-z][A-Za-z0-9]*$"
          },
          "additionalProperties": {
            "$ref": "#/$defs/id"
          }
        }
      }
    },
    "verticalBasis": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "basisId",
        "datum",
        "unit",
        "provenance"
      ],
      "properties": {
        "basisId": {
          "$ref": "#/$defs/id"
        },
        "datum": {
          "enum": [
            "pressureAltitude",
            "geometricMsl",
            "heightAboveEllipsoid",
            "heightAgl"
          ]
        },
        "unit": {
          "enum": [
            "ft",
            "m"
          ]
        },
        "provenance": {
          "enum": [
            "evaluated",
            "estimated",
            "source"
          ]
        },
        "sourceResultId": {
          "$ref": "#/$defs/id"
        },
        "estimateMethod": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "provenance": {
                "const": "evaluated"
              }
            }
          },
          "then": {
            "required": [
              "sourceResultId"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "provenance": {
                "const": "estimated"
              }
            }
          },
          "then": {
            "required": [
              "estimateMethod"
            ]
          }
        }
      ]
    },
    "fuelQuantity": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "value",
        "unit",
        "provenance"
      ],
      "properties": {
        "value": {
          "type": "number",
          "minimum": 0
        },
        "unit": {
          "enum": [
            "lb",
            "kg",
            "usGal",
            "l"
          ]
        },
        "provenance": {
          "enum": [
            "evaluated",
            "estimated"
          ]
        },
        "sourceResultId": {
          "$ref": "#/$defs/id"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "provenance": {
                "const": "evaluated"
              }
            }
          },
          "then": {
            "required": [
              "sourceResultId"
            ]
          }
        }
      ]
    },
    "issue": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "code",
        "severity",
        "message"
      ],
      "properties": {
        "code": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "severity": {
          "enum": [
            "info",
            "warning",
            "error"
          ]
        },
        "message": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "legId": {
          "$ref": "#/$defs/intentId"
        },
        "elementId": {
          "$ref": "#/$defs/intentId"
        }
      }
    },
    "extensions": {
      "type": "object",
      "description": "Optional semantics use reverse-DNS keys. Required unknown semantics are not permitted in v1.",
      "propertyNames": {
        "pattern": "^[a-z][a-z0-9]*(\\.[a-z0-9][a-z0-9-]*)+$"
      }
    },
    "mappingId": {
      "$ref": "#/$defs/sha256",
      "description": "Platform-independent edit-target identity of one resolved leg; see field-dictionary.md."
    },
    "elementKind": {
      "enum": [
        "fix",
        "airway",
        "procedure",
        "direct",
        "discontinuity",
        "coordinate",
        "userWaypoint"
      ]
    },
    "resultOrigin": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "producer",
        "sealCheck"
      ],
      "properties": {
        "producer": {
          "enum": [
            "local",
            "imported"
          ]
        },
        "producerPlatform": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "description": "Diagnostic only, for example darwin-arm64 or linux-x86_64. Never an acceptance input."
        },
        "sealCheck": {
          "enum": [
            "producerSealed",
            "verifiedLocally",
            "notVerified"
          ]
        }
      }
    },
    "admission": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "state"
      ],
      "properties": {
        "state": {
          "enum": [
            "editable",
            "readOnly"
          ]
        },
        "mappingId": {
          "$ref": "#/$defs/mappingId"
        },
        "readOnlyReason": {
          "enum": [
            "legacyMapping",
            "expandedAirway",
            "expandedProcedure",
            "discontinuity",
            "stopEndpoint",
            "ambiguousOwner",
            "directToProjection",
            "untrustedOrigin"
          ]
        },
        "insert": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "afterElementId"
          ],
          "properties": {
            "afterElementId": {
              "oneOf": [
                {
                  "$ref": "#/$defs/id"
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        },
        "delete": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "elementId"
          ],
          "properties": {
            "elementId": {
              "$ref": "#/$defs/intentId"
            }
          }
        },
        "replace": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "elementId",
            "afterElementId"
          ],
          "properties": {
            "elementId": {
              "$ref": "#/$defs/intentId"
            },
            "afterElementId": {
              "oneOf": [
                {
                  "$ref": "#/$defs/id"
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "state": {
                "const": "editable"
              }
            }
          },
          "then": {
            "required": [
              "mappingId"
            ],
            "not": {
              "required": [
                "readOnlyReason"
              ]
            }
          }
        },
        {
          "if": {
            "properties": {
              "state": {
                "const": "readOnly"
              }
            }
          },
          "then": {
            "required": [
              "readOnlyReason"
            ],
            "not": {
              "anyOf": [
                {
                  "required": [
                    "insert"
                  ]
                },
                {
                  "required": [
                    "delete"
                  ]
                },
                {
                  "required": [
                    "replace"
                  ]
                }
              ]
            }
          }
        }
      ]
    },
    "aggregateQuantity": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "value",
        "unit",
        "provenance"
      ],
      "properties": {
        "value": {
          "type": "number",
          "minimum": 0
        },
        "unit": {
          "enum": [
            "lb",
            "kg",
            "usGal",
            "l"
          ]
        },
        "provenance": {
          "enum": [
            "evaluated",
            "estimated"
          ]
        }
      }
    },
    "intentId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:>@/-]*$"
    }
  }
}
