{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://specify.digital/schemas/specify-house-model/2/layout.schema.json",
  "title": "Specify house model layout, version 2",
  "description": "layout.json in a specify-house-model/2 package: the layout that places a house's parts, and the manifest of those parts. See docs/contracts/house-model/v2/README.md. What this schema cannot express (that a reference names something that exists, that an opening lies on its wall, that a part is of its slot's kind, that every list's keys are unique) is checked by the layout check and numbered there; every list is bounded here (HM2-5).",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "standard",
    "house",
    "name",
    "footprint",
    "storeys",
    "rooms",
    "walls",
    "slots",
    "groups",
    "parts"
  ],
  "$defs": {
    "key": {
      "description": "HM2-3. The same characters Specify's configurator uses for row and option keys (HM-7 in version 1). A studio record names its choices by the same keys (facade_color).",
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9_-]*$",
      "maxLength": 64
    },
    "componentId": {
      "description": "A part's name: the house-parts row's componentId.",
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9_-]*$",
      "maxLength": 80
    },
    "metres": {
      "description": "A coordinate or an offset in metres, within 100 m of the house's origin.",
      "type": "number",
      "minimum": -100,
      "maximum": 100
    },
    "length": {
      "description": "A length in metres: more than nothing, at most 100 m.",
      "type": "number",
      "exclusiveMinimum": 0,
      "maximum": 100
    },
    "point": {
      "description": "A point in plan: [x, z] in metres. +X is to the right seen from the front, +Z is towards the front (HM2-4).",
      "type": "array",
      "prefixItems": [
        { "$ref": "#/$defs/metres" },
        { "$ref": "#/$defs/metres" }
      ],
      "items": false,
      "minItems": 2
    },
    "vector": {
      "description": "[x, y, z] in metres.",
      "type": "array",
      "prefixItems": [
        { "$ref": "#/$defs/metres" },
        { "$ref": "#/$defs/metres" },
        { "$ref": "#/$defs/metres" }
      ],
      "items": false,
      "minItems": 3
    },
    "polygon": {
      "description": "A closed outline in plan, its points in order, the last joined to the first.",
      "type": "array",
      "items": { "$ref": "#/$defs/point" },
      "minItems": 3,
      "maxItems": 64
    },
    "yaw": {
      "description": "A turn about +Y in degrees, anticlockwise seen from above.",
      "type": "number",
      "minimum": -360,
      "maximum": 360
    },
    "names": {
      "description": "What a customer reads, by language (en, da, sv, ...). Optional: the studio record's words win where it has them.",
      "type": "object",
      "propertyNames": { "pattern": "^[a-z]{2}$" },
      "additionalProperties": {
        "type": "string",
        "minLength": 1,
        "maxLength": 80
      },
      "maxProperties": 16
    },
    "partKind": {
      "description": "A part's kind, the house-parts collection's vocabulary (studioHouse/v71Components.ts HOUSE_PART_KINDS).",
      "enum": [
        "furniture",
        "window",
        "door",
        "roof",
        "facade",
        "structure",
        "kitchen",
        "fitting",
        "appliance",
        "surface",
        "outdoor",
        "outbuilding",
        "solar",
        "setting"
      ]
    },
    "roomType": {
      "description": "What a room is, which the planner reads (the furniture each kind of room takes).",
      "enum": [
        "entrance",
        "hall",
        "living",
        "kitchen",
        "dining",
        "bedroom",
        "office",
        "bathroom",
        "wc",
        "utility",
        "storage",
        "stair",
        "other"
      ]
    },
    "storey": {
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "floorLevel", "ceilingHeight"],
      "properties": {
        "key": { "$ref": "#/$defs/key" },
        "floorLevel": {
          "description": "The storey's finished floor, in metres above the ground (Y = 0). The ground storey of a house on a raised floor is above 0.",
          "type": "number",
          "minimum": -10,
          "maximum": 30
        },
        "conceptOnly": { "type": "boolean", "description": "A concept cutaway excluded from house area calculations." },
        "ceilingHeight": {
          "description": "Finished floor to finished ceiling.",
          "type": "number",
          "exclusiveMinimum": 0,
          "maximum": 10
        },
        "footprint": {
          "description": "The storey's outside outline, walls included, where it is not the house's footprint (an upper storey set back from the one below). Absent, the house's. Its rooms and floor openings lie inside it (HM2-32, HM2-27).",
          "$ref": "#/$defs/polygon"
        },
        "names": { "$ref": "#/$defs/names" }
      }
    },
    "room": {
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "type", "storey", "polygon"],
      "properties": {
        "key": { "$ref": "#/$defs/key" },
        "type": { "$ref": "#/$defs/roomType" },
        "storey": { "$ref": "#/$defs/key" },
        "polygon": { "$ref": "#/$defs/polygon" },
        "names": { "$ref": "#/$defs/names" }
      }
    },
    "opening": {
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "type", "along", "width", "height"],
      "properties": {
        "key": { "$ref": "#/$defs/key" },
        "type": {
          "description": "door: a hinged leaf. sliding-door: a leaf that slides. window: a window, with a sill. doorway: a hole with no leaf.",
          "enum": ["door", "sliding-door", "window", "doorway"]
        },
        "along": {
          "description": "From the wall's `from` to the opening's centre, along the wall.",
          "type": "number",
          "minimum": 0,
          "maximum": 100
        },
        "width": { "$ref": "#/$defs/length" },
        "height": { "$ref": "#/$defs/length" },
        "sill": {
          "description": "A window's: its bottom above the storey's floor.",
          "type": "number",
          "minimum": 0,
          "maximum": 10
        },
        "hinge": {
          "description": "A door's: which end of the opening its leaf hangs from, the end nearer the wall's `from` or its `to`.",
          "enum": ["start", "end"]
        },
        "opensInto": {
          "description": "A door's: the room its leaf swings into, or outside.",
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_-]*$",
          "maxLength": 64
        }
      }
    },
    "wall": {
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "storey", "kind", "from", "to", "thickness"],
      "properties": {
        "key": { "$ref": "#/$defs/key" },
        "storey": { "$ref": "#/$defs/key" },
        "kind": { "enum": ["external", "internal"] },
        "from": { "$ref": "#/$defs/point" },
        "to": { "$ref": "#/$defs/point" },
        "thickness": { "type": "number", "exclusiveMinimum": 0, "maximum": 1 },
        "height": {
          "description": "Absent, the storey's ceiling height.",
          "$ref": "#/$defs/length"
        },
        "bearing": {
          "description": "Whether the wall carries what stands on it. Absent, true for an external wall and false for an internal one. A bearing wall above the lowest storey stands on a bearing wall of the storey below (HM2-29).",
          "type": "boolean"
        },
        "openings": {
          "type": "array",
          "items": { "$ref": "#/$defs/opening" },
          "maxItems": 32
        }
      }
    },
    "stair": {
      "description": "One straight flight from a storey to the next, or with a `landing` two flights turning a quarter (HM2-21 to HM2-26). Its part sits in a slot anchored to it.",
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "from", "to", "foot", "head", "width", "headroom"],
      "properties": {
        "key": { "$ref": "#/$defs/key" },
        "from": {
          "description": "The storey the flight's foot stands on.",
          "$ref": "#/$defs/key"
        },
        "to": {
          "description": "The storey the flight arrives at: the next one up.",
          "$ref": "#/$defs/key"
        },
        "foot": {
          "description": "In plan, the centre of the bottom step's front edge, on the `from` storey's floor.",
          "$ref": "#/$defs/point"
        },
        "head": {
          "description": "In plan, the centre of the edge where the flight meets the `to` storey's floor. Foot to head is the flight's run and its direction.",
          "$ref": "#/$defs/point"
        },
        "landing": {
          "description": "A quarter-turn stair's turn (T-261114-UCXG): in plan, where the first flight's centre line, foot to landing, meets the second's, landing to head, at right angles; the middle of a level landing the stair's width square. Absent, foot to head is one straight flight.",
          "$ref": "#/$defs/point"
        },
        "width": {
          "description": "The flight's clear width.",
          "type": "number",
          "exclusiveMinimum": 0,
          "maximum": 3
        },
        "headroom": {
          "description": "The clear height over the flight, measured straight up from its pitch line (the line through the steps' front edges).",
          "type": "number",
          "exclusiveMinimum": 0,
          "maximum": 10
        },
        "floorOpening": {
          "description": "The opening in the `to` storey's floor the flight rises through (HM2-25).",
          "$ref": "#/$defs/key"
        },
        "names": { "$ref": "#/$defs/names" }
      }
    },
    "floorOpening": {
      "description": "A hole in a storey's floor: the stairwell a flight rises through, or a void guarded all round (HM2-27).",
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "storey", "polygon"],
      "properties": {
        "key": { "$ref": "#/$defs/key" },
        "storey": {
          "description": "The storey whose floor it is cut in: never the lowest.",
          "$ref": "#/$defs/key"
        },
        "polygon": { "$ref": "#/$defs/polygon" },
        "guarded": {
          "description": "True: a void with a guard all round it, which no stair rises through (a double-height hall).",
          "type": "boolean"
        }
      }
    },
    "anchor": {
      "description": "Where a slot's offset is measured from: exactly one of the house's footprint, a storey, a room, a wall, an opening or a stair (HM2-40).",
      "type": "object",
      "additionalProperties": false,
      "minProperties": 1,
      "maxProperties": 1,
      "properties": {
        "footprint": { "const": true },
        "storey": { "$ref": "#/$defs/key" },
        "room": { "$ref": "#/$defs/key" },
        "wall": { "$ref": "#/$defs/key" },
        "opening": { "$ref": "#/$defs/key" },
        "stair": { "$ref": "#/$defs/key" }
      }
    },
    "slot": {
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "anchor", "takes", "part"],
      "properties": {
        "key": { "$ref": "#/$defs/key" },
        "anchor": { "$ref": "#/$defs/anchor" },
        "offset": {
          "description": "From the anchor's origin, in the anchor's frame. Absent, [0, 0, 0].",
          "$ref": "#/$defs/vector"
        },
        "yaw": {
          "description": "Absent, 0: the part's front faces the frame's +Z.",
          "$ref": "#/$defs/yaw"
        },
        "takes": { "$ref": "#/$defs/partKind" },
        "alsoTakes": {
          "description": "Further kinds of part the slot holds, where a choice swaps in a part the library sorts under another kind than `takes` (HM2-12). Absent, only `takes`.",
          "type": "array",
          "items": { "$ref": "#/$defs/partKind" },
          "minItems": 1,
          "maxItems": 13,
          "uniqueItems": true
        },
        "part": {
          "description": "The default part: what sits here until a choice swaps it.",
          "$ref": "#/$defs/componentId"
        },
        "shown": {
          "description": "Absent, true. False: hidden until a choice shows it (a garage, an island).",
          "type": "boolean"
        },
        "materials": {
          "description": "The slot's own materials, set whatever is chosen, before any option's patch.",
          "type": "array",
          "items": { "$ref": "#/$defs/finish" },
          "maxItems": 16
        }
      }
    },
    "materialPatch": {
      "type": "object",
      "additionalProperties": false,
      "required": ["slots", "material", "colour"],
      "properties": {
        "slots": {
          "type": "array",
          "items": { "$ref": "#/$defs/key" },
          "minItems": 1,
          "maxItems": 64
        },
        "material": {
          "description": "The material slot in the part, `mat:<material>` (HM-15 in version 1) or, in a library part, `<material>`; compared as `match` says.",
          "$ref": "#/$defs/key"
        },
        "colour": { "type": "string", "pattern": "^#[0-9a-f]{6}$" },
        "roughness": { "type": "number", "minimum": 0, "maximum": 1 },
        "textureKind": { "$ref": "#/$defs/textureKind" },
        "match": { "$ref": "#/$defs/materialMatch" },
        "hidden": {
          "description": "Present, the material is not drawn at all: a part's own detail a choice replaces with a part of its own (a cabinet's handle). The colour is then not read.",
          "const": true
        },
        "roomOnly": {
          "description": "Present, the patch is set only where a design chooses the option for one room, and only on that room's slots, never by the house's own choice (T-261109-YNJ4): a wet room's floor, which the house's floor does not reach but a stone floor chosen for the bathroom does.",
          "const": true
        }
      }
    },
    "finish": {
      "description": "A material a slot sets on its part whatever is chosen, before any option patches it: a material patch on the slot's own part.",
      "type": "object",
      "additionalProperties": false,
      "required": ["material", "colour"],
      "properties": {
        "material": { "$ref": "#/$defs/key" },
        "colour": { "type": "string", "pattern": "^#[0-9a-f]{6}$" },
        "roughness": { "type": "number", "minimum": 0, "maximum": 1 },
        "textureKind": { "$ref": "#/$defs/textureKind" },
        "match": { "$ref": "#/$defs/materialMatch" },
        "hidden": {
          "description": "Present, the material is not drawn at all: a part's own detail a choice replaces with a part of its own (a cabinet's handle). The colour is then not read.",
          "const": true
        }
      }
    },
    "textureKind": {
      "description": "The studio's own finish the material is drawn with, tinted by the colour. Absent, the part keeps its own texture. board_on_board, tongue_groove and shiplap are wood facade profiles drawn over the wood finish (T-261112-TRFN); plank_strip and plank_wide are a wood floor laid in narrower (128 mm) or wider (256 mm) planks than wood's 183 mm (T-261111-PW4K); tile_30x60, tile_10x20, tile_30x30 and tile_10x10 are tile laid in that size, in centimetres, the first two in a half bond, where tile's is 60 x 60 (T-261112-BT6F).",
      "enum": ["wood", "stone", "tile", "paint", "board_on_board", "tongue_groove", "shiplap", "plank_strip", "plank_wide", "tile_30x60", "tile_10x20", "tile_30x30", "tile_10x10"]
    },
    "materialMatch": {
      "description": "How `material` is compared with a part's material names (without a `mat:` prefix). exact (absent): equal. prefix: equal, or beginning with `<material>_`. node: `material` names the part's nodes instead, each named `<material>__<its material>` (T-261113-RV8E): with `hidden`, a part's piece that shares a material with what stays drawn, as a roof's rainwater goods do.",
      "enum": ["exact", "prefix", "node"]
    },
    "option": {
      "type": "object",
      "additionalProperties": false,
      "required": ["key"],
      "properties": {
        "key": { "$ref": "#/$defs/key" },
        "plan": {
          "description": "Plan geometry added or replaced by this option.",
          "type": "object",
          "additionalProperties": false,
          "minProperties": 1,
          "properties": {
            "omitWalls": { "type": "array", "items": { "$ref": "#/$defs/key" }, "uniqueItems": true, "maxItems": 32 },
            "storeys": { "type": "array", "items": { "$ref": "#/$defs/storey" }, "maxItems": 4 },
            "rooms": { "type": "array", "items": { "$ref": "#/$defs/room" }, "maxItems": 32 },
            "keepOuts": { "type": "array", "items": { "$ref": "#/$defs/keepOut" }, "maxItems": 32 },
            "walls": { "type": "array", "items": { "$ref": "#/$defs/wall" }, "maxItems": 32 },
            "stairs": { "type": "array", "items": { "$ref": "#/$defs/stair" }, "maxItems": 16 },
            "floorOpenings": { "type": "array", "items": { "$ref": "#/$defs/floorOpening" }, "maxItems": 32 }
          }
        },
        "parts": {
          "description": "Slot key to the part that sits there for this option.",
          "type": "object",
          "propertyNames": { "$ref": "#/$defs/key" },
          "additionalProperties": { "$ref": "#/$defs/componentId" },
          "maxProperties": 256
        },
        "materials": {
          "type": "array",
          "items": { "$ref": "#/$defs/materialPatch" },
          "maxItems": 32
        },
        "show": {
          "type": "array",
          "items": { "$ref": "#/$defs/key" },
          "maxItems": 256
        },
        "hide": {
          "type": "array",
          "items": { "$ref": "#/$defs/key" },
          "maxItems": 256
        },
        "moves": {
          "description": "Slot key to where the slot stands while this option is chosen (HM2-45).",
          "type": "object",
          "propertyNames": { "$ref": "#/$defs/key" },
          "additionalProperties": { "$ref": "#/$defs/move" },
          "maxProperties": 256
        }
      }
    },
    "move": {
      "description": "A slot's offset, its yaw or both, in its anchor's frame as the slot's own are (§ A5). What a move leaves out is left as it was.",
      "type": "object",
      "additionalProperties": false,
      "minProperties": 1,
      "properties": {
        "offset": { "$ref": "#/$defs/vector" },
        "yaw": { "$ref": "#/$defs/yaw" }
      }
    },
    "group": {
      "description": "One thing the customer chooses. Its key binds to the configurator row of the same key; the studio record narrows, words and prices it.",
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "default", "options"],
      "properties": {
        "key": { "$ref": "#/$defs/key" },
        "default": { "$ref": "#/$defs/key" },
        "options": {
          "type": "array",
          "items": { "$ref": "#/$defs/option" },
          "minItems": 1,
          "maxItems": 32
        }
      }
    },
    "combination": {
      "description": "What two to four choices set together (HM2-46): applied after every group, in the list's order, when each choice it names holds the option it names. Its effects are an option's.",
      "type": "object",
      "additionalProperties": false,
      "required": ["when"],
      "properties": {
        "when": {
          "description": "A group's or a room layout's key to one of its option keys.",
          "type": "object",
          "propertyNames": { "$ref": "#/$defs/key" },
          "additionalProperties": { "$ref": "#/$defs/key" },
          "minProperties": 2,
          "maxProperties": 4
        },
        "parts": { "$ref": "#/$defs/option/properties/parts" },
        "materials": { "$ref": "#/$defs/option/properties/materials" },
        "show": { "$ref": "#/$defs/option/properties/show" },
        "hide": { "$ref": "#/$defs/option/properties/hide" },
        "moves": { "$ref": "#/$defs/option/properties/moves" }
      }
    },
    "alternative": {
      "description": "A room's furnished arrangements, one chosen as a whole: each option is the set of slots placed when it is chosen.",
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "room", "default", "options"],
      "properties": {
        "key": { "$ref": "#/$defs/key" },
        "room": { "$ref": "#/$defs/key" },
        "default": { "$ref": "#/$defs/key" },
        "options": {
          "type": "array",
          "minItems": 2,
          "maxItems": 8,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["key", "slots"],
            "properties": {
              "key": { "$ref": "#/$defs/key" },
              "slots": {
                "type": "array",
                "items": { "$ref": "#/$defs/slot" },
                "maxItems": 128
              }
            }
          }
        }
      }
    },
    "viewpoint": {
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "eye", "target"],
      "properties": {
        "key": { "$ref": "#/$defs/key" },
        "eye": { "$ref": "#/$defs/vector" },
        "target": { "$ref": "#/$defs/vector" },
        "room": {
          "description": "A viewpoint inside a room names it.",
          "$ref": "#/$defs/key"
        },
        "fov": {
          "description": "Vertical field of view in degrees. Absent, the studio's.",
          "type": "number",
          "minimum": 20,
          "maximum": 100
        },
        "names": { "$ref": "#/$defs/names" }
      }
    },
    "keepOut": {
      "description": "A stated area the planner keeps furniture out of, beyond what it derives from doors and windows (HM2-61).",
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "room", "kind", "polygon"],
      "properties": {
        "key": { "$ref": "#/$defs/key" },
        "room": { "$ref": "#/$defs/key" },
        "kind": { "enum": ["approach", "service", "clearance"] },
        "polygon": { "$ref": "#/$defs/polygon" }
      }
    },
    "route": {
      "description": "A path the planner keeps clear, stated where a door does not imply it.",
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "room", "from", "to"],
      "properties": {
        "key": { "$ref": "#/$defs/key" },
        "room": { "$ref": "#/$defs/key" },
        "from": { "$ref": "#/$defs/point" },
        "to": { "$ref": "#/$defs/point" },
        "width": {
          "description": "Absent, the planner's route width.",
          "type": "number",
          "minimum": 0.3,
          "maximum": 3
        }
      }
    },
    "part": {
      "type": "object",
      "additionalProperties": false,
      "required": ["componentId", "kind", "origin", "sha256"],
      "properties": {
        "componentId": { "$ref": "#/$defs/componentId" },
        "kind": { "$ref": "#/$defs/partKind" },
        "origin": {
          "description": "specify: a part of Specify's shared library, which the package does not carry. merchant: the store's own, carried in the package's parts/ folder.",
          "enum": ["specify", "merchant"]
        },
        "file": {
          "description": "A merchant part's file in the package: parts/<componentId>.glb.",
          "type": "string",
          "maxLength": 100
        },
        "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
      }
    }
  },
  "properties": {
    "standard": { "const": "specify-house-model/2" },
    "house": { "$ref": "#/$defs/key" },
    "name": { "type": "string", "minLength": 1, "maxLength": 120 },
    "footprint": {
      "description": "The house's outside outline at the ground, walls included.",
      "$ref": "#/$defs/polygon"
    },
    "storeys": {
      "description": "Ground first, each above the one before (HM2-20).",
      "type": "array",
      "items": { "$ref": "#/$defs/storey" },
      "minItems": 1,
      "maxItems": 4
    },
    "rooms": {
      "type": "array",
      "items": { "$ref": "#/$defs/room" },
      "minItems": 1,
      "maxItems": 64
    },
    "walls": {
      "type": "array",
      "items": { "$ref": "#/$defs/wall" },
      "minItems": 1,
      "maxItems": 256
    },
    "stairs": {
      "description": "The flights between storeys (HM2-21).",
      "type": "array",
      "items": { "$ref": "#/$defs/stair" },
      "maxItems": 16
    },
    "floorOpenings": {
      "type": "array",
      "items": { "$ref": "#/$defs/floorOpening" },
      "maxItems": 32
    },
    "slots": {
      "type": "array",
      "items": { "$ref": "#/$defs/slot" },
      "minItems": 1,
      "maxItems": 1024
    },
    "groups": {
      "type": "array",
      "items": { "$ref": "#/$defs/group" }
    },
    "alternatives": {
      "type": "array",
      "items": { "$ref": "#/$defs/alternative" },
      "maxItems": 32
    },
    "combinations": {
      "description": "Parts, presence, materials and places two or more choices set together (HM2-46).",
      "type": "array",
      "items": { "$ref": "#/$defs/combination" },
      "maxItems": 512
    },
    "viewpoints": {
      "type": "array",
      "items": { "$ref": "#/$defs/viewpoint" },
      "maxItems": 64
    },
    "keepOuts": {
      "type": "array",
      "items": { "$ref": "#/$defs/keepOut" },
      "maxItems": 256
    },
    "routes": {
      "type": "array",
      "items": { "$ref": "#/$defs/route" },
      "maxItems": 128
    },
    "parts": {
      "description": "The manifest: every part the layout names, once (HM2-10).",
      "type": "array",
      "items": { "$ref": "#/$defs/part" },
      "minItems": 1,
      "maxItems": 1024
    }
  }
}
