{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Illustrative single-view floor plan contract",
  "type": "object",
  "properties": {
    "schema_version": {
      "const": "1.0.0"
    },
    "coordinate_frame": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "units": {
          "const": "m"
        },
        "origin": {
          "const": "local-plan"
        },
        "x_axis": {
          "const": "right"
        },
        "y_axis": {
          "const": "up"
        },
        "scale_evidence": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "id",
        "units",
        "origin",
        "x_axis",
        "y_axis",
        "scale_evidence"
      ],
      "additionalProperties": false
    },
    "exterior_space_id": {
      "type": "string",
      "minLength": 1
    },
    "rooms": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "$ref": "#/$defs/room"
      }
    },
    "openings": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/opening"
      }
    },
    "connections": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "opening_id": {
            "type": "string",
            "minLength": 1
          },
          "from": {
            "type": "string",
            "minLength": 1
          },
          "to": {
            "type": "string",
            "minLength": 1
          },
          "status": {
            "enum": [
              "candidate",
              "reviewed"
            ]
          }
        },
        "required": [
          "opening_id",
          "from",
          "to",
          "status"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "schema_version",
    "coordinate_frame",
    "exterior_space_id",
    "rooms",
    "openings",
    "connections"
  ],
  "additionalProperties": false,
  "$defs": {
    "point": {
      "type": "array",
      "prefixItems": [
        {
          "type": "number"
        },
        {
          "type": "number"
        }
      ],
      "items": false,
      "minItems": 2,
      "maxItems": 2
    },
    "room": {
      "type": "object",
      "properties": {
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "polygon": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/point"
          },
          "minItems": 4
        },
        "status": {
          "enum": [
            "candidate",
            "reviewed"
          ]
        },
        "evidence": {
          "$ref": "#/$defs/evidence"
        }
      },
      "required": [
        "name",
        "polygon",
        "status",
        "evidence"
      ],
      "additionalProperties": false
    },
    "opening": {
      "type": "object",
      "properties": {
        "kind": {
          "enum": [
            "door",
            "window",
            "passage",
            "unknown"
          ]
        },
        "span": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/point"
          },
          "minItems": 2,
          "maxItems": 2
        },
        "spaces": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 2,
          "maxItems": 2,
          "uniqueItems": true
        },
        "status": {
          "enum": [
            "candidate",
            "reviewed"
          ]
        },
        "evidence": {
          "$ref": "#/$defs/evidence"
        }
      },
      "required": [
        "kind",
        "span",
        "spaces",
        "status",
        "evidence"
      ],
      "additionalProperties": false
    },
    "evidence": {
      "type": "object",
      "properties": {
        "sheet": {
          "type": "string",
          "minLength": 1
        },
        "revision": {
          "type": "string",
          "minLength": 1
        },
        "view": {
          "type": "string",
          "minLength": 1
        },
        "page_index": {
          "type": "integer",
          "minimum": 0
        }
      },
      "required": [
        "sheet",
        "revision",
        "view",
        "page_index"
      ],
      "additionalProperties": false
    }
  }
}
