{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.cobblr.xyz/schemas/cobblr-floorplan-1.json",
  "title": "cobblr-floorplan/1",
  "description": "A home or workshop as Cobblr's floor plan: rooms with their size, interior walls and openings, zones, and containers (racks, cabinets, toolboxes) with their shelves and drawers. Integers in millimetres; x right and y down from a room's top-left corner.",
  "type": "object",
  "properties": {
    "format": {
      "const": "cobblr-floorplan/1"
    },
    "units_entered": {
      "type": "string",
      "enum": [
        "mm",
        "cm",
        "m",
        "in",
        "ft"
      ]
    },
    "site": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        }
      },
      "required": [
        "name"
      ]
    },
    "rooms": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "level": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200,
            "description": "The floor or level it is on (an area that groups rooms)."
          },
          "w_mm": {
            "type": "number",
            "exclusiveMinimum": 0,
            "description": "Its width, left to right, in mm."
          },
          "d_mm": {
            "type": "number",
            "exclusiveMinimum": 0,
            "description": "Its depth, top to bottom, in mm."
          },
          "walls": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "x1": {
                  "type": "number"
                },
                "y1": {
                  "type": "number"
                },
                "x2": {
                  "type": "number"
                },
                "y2": {
                  "type": "number"
                },
                "openings": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "at_mm": {
                        "type": "number",
                        "minimum": 0,
                        "description": "How far along the wall from its first end, in mm."
                      },
                      "w_mm": {
                        "type": "number",
                        "exclusiveMinimum": 0,
                        "description": "Its width, in mm."
                      },
                      "kind": {
                        "type": "string",
                        "enum": [
                          "door",
                          "window",
                          "opening"
                        ],
                        "description": "door, window or opening."
                      }
                    },
                    "required": [
                      "at_mm",
                      "w_mm"
                    ]
                  }
                }
              },
              "required": [
                "x1",
                "y1",
                "x2",
                "y2"
              ]
            }
          },
          "zones": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 200
                },
                "x_mm": {
                  "type": "number"
                },
                "y_mm": {
                  "type": "number"
                },
                "w_mm": {
                  "type": "number",
                  "exclusiveMinimum": 0
                },
                "d_mm": {
                  "type": "number",
                  "exclusiveMinimum": 0
                }
              },
              "required": [
                "name",
                "x_mm",
                "y_mm",
                "w_mm",
                "d_mm"
              ]
            }
          },
          "containers": {
            "type": "array",
            "items": {
              "$ref": "#/$defs/container"
            }
          }
        },
        "required": [
          "name",
          "w_mm",
          "d_mm"
        ]
      },
      "minItems": 1
    }
  },
  "required": [
    "format",
    "rooms"
  ],
  "$defs": {
    "container": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "x_mm": {
          "type": "number"
        },
        "y_mm": {
          "type": "number"
        },
        "w_mm": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "d_mm": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "h_mm": {
          "type": "number",
          "exclusiveMinimum": 0,
          "description": "Its height, in mm: the height of its front face."
        },
        "wall_mounted": {
          "type": "boolean"
        },
        "face": {
          "type": "object",
          "properties": {
            "shelves": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "from_bottom_mm": {
                    "type": "number",
                    "minimum": 0,
                    "description": "The height of the shelf's surface above the floor, in mm."
                  }
                },
                "required": [
                  "name",
                  "from_bottom_mm"
                ]
              }
            }
          }
        },
        "containers": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/container"
          }
        }
      },
      "required": [
        "name",
        "x_mm",
        "y_mm",
        "w_mm",
        "d_mm"
      ]
    }
  }
}
