{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://postflight.co/aeronautiql/planning/v1_1/edits/mapping.schema.json",
  "title": "Occurrence edit mapping v1.1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "documentId",
    "commitId",
    "legId",
    "resolutionMappingId",
    "navigationDataRevision",
    "context",
    "vertices",
    "edges",
    "editMappingId"
  ],
  "properties": {
    "schemaVersion": {
      "const": "1.1"
    },
    "documentId": {
      "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/intentId"
    },
    "commitId": {
      "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/intentId"
    },
    "legId": {
      "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/intentId"
    },
    "resolutionMappingId": {
      "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/mappingId"
    },
    "navigationDataRevision": {
      "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/id"
    },
    "context": {
      "$ref": "#/$defs/context"
    },
    "vertices": {
      "type": "array",
      "maxItems": 20000,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "vertexId",
          "pointIndex",
          "elementId",
          "state"
        ],
        "properties": {
          "vertexId": {
            "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/id"
          },
          "pointIndex": {
            "type": "integer",
            "minimum": 0
          },
          "elementId": {
            "oneOf": [
              {
                "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/intentId"
              },
              {
                "type": "null"
              }
            ]
          },
          "state": {
            "enum": [
              "editable",
              "readOnly"
            ]
          },
          "readOnlyReason": {
            "enum": [
              "terminal",
              "stopEndpoint",
              "expandedAirway",
              "expandedProcedure",
              "ambiguousOwner",
              "discontinuity"
            ]
          },
          "terminalIndex": {
            "type": "integer",
            "minimum": 0,
            "maximum": 1
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "state": {
                  "const": "readOnly"
                }
              }
            },
            "then": {
              "required": [
                "readOnlyReason"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "state": {
                  "const": "editable"
                }
              }
            },
            "then": {
              "not": {
                "anyOf": [
                  {
                    "required": [
                      "readOnlyReason"
                    ]
                  },
                  {
                    "required": [
                      "terminalIndex"
                    ]
                  }
                ]
              }
            }
          },
          {
            "if": {
              "properties": {
                "readOnlyReason": {
                  "const": "terminal"
                }
              },
              "required": [
                "readOnlyReason"
              ]
            },
            "then": {
              "required": [
                "terminalIndex"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "state": {
                  "const": "editable"
                }
              }
            },
            "then": {
              "properties": {
                "elementId": {
                  "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/intentId"
                }
              }
            }
          }
        ]
      }
    },
    "edges": {
      "type": "array",
      "maxItems": 19999,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "edgeId",
          "fromPointIndex",
          "toPointIndex",
          "fromElementId",
          "toElementId",
          "interiorOfElementId",
          "state"
        ],
        "properties": {
          "edgeId": {
            "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/id"
          },
          "fromPointIndex": {
            "type": "integer",
            "minimum": 0
          },
          "toPointIndex": {
            "type": "integer",
            "minimum": 1
          },
          "fromElementId": {
            "oneOf": [
              {
                "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/intentId"
              },
              {
                "type": "null"
              }
            ]
          },
          "toElementId": {
            "oneOf": [
              {
                "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/intentId"
              },
              {
                "type": "null"
              }
            ]
          },
          "interiorOfElementId": {
            "oneOf": [
              {
                "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/intentId"
              },
              {
                "type": "null"
              }
            ]
          },
          "state": {
            "enum": [
              "editable",
              "readOnly"
            ]
          },
          "readOnlyReason": {
            "enum": [
              "terminal",
              "stopEndpoint",
              "expandedAirway",
              "expandedProcedure",
              "ambiguousOwner",
              "discontinuity"
            ]
          },
          "terminalIndex": {
            "type": "integer",
            "minimum": 0,
            "maximum": 1
          },
          "insertion": {
            "oneOf": [
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "kind"
                ],
                "properties": {
                  "kind": {
                    "const": "beforeFirst"
                  }
                }
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "kind",
                  "elementId"
                ],
                "properties": {
                  "kind": {
                    "const": "afterElement"
                  },
                  "elementId": {
                    "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/intentId"
                  }
                }
              }
            ]
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "state": {
                  "const": "readOnly"
                }
              }
            },
            "then": {
              "required": [
                "readOnlyReason"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "state": {
                  "const": "editable"
                }
              }
            },
            "then": {
              "not": {
                "anyOf": [
                  {
                    "required": [
                      "readOnlyReason"
                    ]
                  },
                  {
                    "required": [
                      "terminalIndex"
                    ]
                  }
                ]
              }
            }
          },
          {
            "if": {
              "properties": {
                "readOnlyReason": {
                  "const": "terminal"
                }
              },
              "required": [
                "readOnlyReason"
              ]
            },
            "then": {
              "required": [
                "terminalIndex"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "state": {
                  "const": "editable"
                }
              }
            },
            "then": {
              "properties": {
                "interiorOfElementId": {
                  "type": "null"
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "state": {
                  "const": "editable"
                }
              }
            },
            "then": {
              "required": [
                "insertion"
              ]
            },
            "else": {
              "not": {
                "required": [
                  "insertion"
                ]
              }
            }
          }
        ]
      }
    },
    "editMappingId": {
      "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/mappingId"
    }
  },
  "$defs": {
    "context": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "slot",
        "slotRevision",
        "navigationContextRevision",
        "mode"
      ],
      "properties": {
        "slot": {
          "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/id"
        },
        "slotRevision": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "navigationContextRevision": {
          "$ref": "https://postflight.co/aeronautiql/planning/v1/results/common.schema.json#/$defs/id"
        },
        "mode": {
          "const": "planning"
        }
      }
    }
  }
}
