{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://app.domusvox.de/schema/package-elements-1.json",
  "title": "DomusVox element types",
  "description": "The elements a package brings: furniture and building elements with their placement rule. Unknown fields are allowed and ignored.",
  "type": "object",
  "required": ["schema", "elements"],
  "properties": {
    "schema": {
      "const": 1
    },
    "elements": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/element"
      }
    }
  },
  "$defs": {
    "texts": {
      "type": "object",
      "required": ["en", "de"],
      "propertyNames": {
        "pattern": "^[a-z]{2}(-[A-Z]{2})?$"
      },
      "additionalProperties": {
        "type": "string",
        "minLength": 1,
        "maxLength": 300
      }
    },
    "range": {
      "type": "array",
      "prefixItems": [
        {
          "type": "number",
          "exclusiveMinimum": 0
        },
        {
          "type": "number",
          "exclusiveMinimum": 0
        }
      ],
      "minItems": 2,
      "maxItems": 2
    },
    "element": {
      "type": "object",
      "required": ["key", "category", "names", "spoken", "size", "placement"],
      "properties": {
        "key": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]{0,59}$"
        },
        "category": {
          "enum": [
            "door",
            "window",
            "opening",
            "stairs",
            "seating",
            "table",
            "bed",
            "storage",
            "kitchen",
            "appliance",
            "bath",
            "heating",
            "fireplace",
            "lighting",
            "electrical",
            "media",
            "plant",
            "decor",
            "other"
          ]
        },
        "names": {
          "$ref": "#/$defs/texts"
        },
        "spoken": {
          "$ref": "#/$defs/texts",
          "description": "A short sentence for screen readers, e.g. \"Sofa for three, 2.2 metres wide\"."
        },
        "size": {
          "type": "object",
          "required": ["width", "depth", "height"],
          "description": "Default size in metres. For elements in a wall, depth follows the wall.",
          "properties": {
            "width": {
              "type": "number",
              "exclusiveMinimum": 0,
              "maximum": 20
            },
            "depth": {
              "type": "number",
              "exclusiveMinimum": 0,
              "maximum": 20
            },
            "height": {
              "type": "number",
              "exclusiveMinimum": 0,
              "maximum": 10
            },
            "elevation": {
              "type": "number",
              "minimum": 0,
              "maximum": 10,
              "description": "Height above the floor, e.g. a window sill."
            }
          }
        },
        "resize": {
          "type": "object",
          "description": "Allowed range per side in metres; a side without a range keeps its size.",
          "properties": {
            "width": {
              "$ref": "#/$defs/range"
            },
            "depth": {
              "$ref": "#/$defs/range"
            },
            "height": {
              "$ref": "#/$defs/range"
            }
          }
        },
        "placement": {
          "type": "object",
          "required": ["rule"],
          "properties": {
            "rule": {
              "enum": ["in-wall", "at-wall", "free", "under", "on", "ceiling"]
            },
            "gap": {
              "type": "number",
              "minimum": 0,
              "maximum": 2,
              "description": "at-wall: distance to the wall in metres."
            },
            "categories": {
              "type": "array",
              "description": "under / on: the categories this element fits under or stands on.",
              "items": {
                "enum": [
                  "door",
                  "window",
                  "opening",
                  "stairs",
                  "seating",
                  "table",
                  "bed",
                  "storage",
                  "kitchen",
                  "appliance",
                  "bath",
                  "heating",
                  "fireplace",
                  "lighting",
                  "electrical",
                  "media",
                  "plant",
                  "decor",
                  "other"
                ]
              }
            },
            "swing": {
              "enum": ["none", "single", "double", "sliding"],
              "description": "in-wall: how a door or window opens; the editor draws the arc and lets people flip the side."
            }
          }
        },
        "clearance": {
          "type": "array",
          "description": "Areas that must stay free, as a side and a depth in metres.",
          "items": {
            "type": "object",
            "required": ["side", "depth"],
            "properties": {
              "side": {
                "enum": ["front", "back", "left", "right", "swing"]
              },
              "depth": {
                "type": "number",
                "exclusiveMinimum": 0,
                "maximum": 3
              }
            }
          }
        },
        "symbol": {
          "type": "string",
          "pattern": "^[a-z0-9_/.-]+\\.svg$"
        },
        "model": {
          "type": "string",
          "pattern": "^[a-z0-9_/.-]+\\.glb$",
          "description": "3D model (glTF binary), light enough for the tablet. Metres, Y up, origin at the centre of the footprint on the floor, front towards +Z (the room side for elements at a wall). Without a model the 3D view draws a block of size."
        },
        "modelDetailed": {
          "type": "string",
          "pattern": "^models/detailed/[a-z0-9_/.-]+\\.glb$",
          "description": "Optional heavier model with more detail for desktops, under models/detailed/; same convention as model."
        },
        "modelFit": {
          "enum": ["stretch", "uniform"],
          "description": "How the model is brought to the chosen size: stretch each side (default) or keep proportions and fit inside."
        },
        "variants": {
          "type": "array",
          "description": "Versions of the element that differ in looks only, e.g. the fronts of a wardrobe. The first is the default and its model is the element's model.",
          "minItems": 2,
          "maxItems": 12,
          "items": {
            "type": "object",
            "required": ["key", "names", "model"],
            "properties": {
              "key": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,39}$"
              },
              "names": {
                "$ref": "#/$defs/texts"
              },
              "model": {
                "type": "string",
                "pattern": "^[a-z0-9_/.-]+\\.glb$"
              },
              "symbol": {
                "type": "string",
                "pattern": "^[a-z0-9_/.-]+\\.svg$"
              }
            }
          }
        },
        "colours": {
          "type": "array",
          "description": "Parts whose colour people choose, e.g. body and front. slot is the name of a material in every model of the element; the first option is the default.",
          "maxItems": 4,
          "items": {
            "type": "object",
            "required": ["slot", "names", "options"],
            "properties": {
              "slot": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,19}$"
              },
              "names": {
                "$ref": "#/$defs/texts"
              },
              "options": {
                "type": "array",
                "minItems": 1,
                "maxItems": 24,
                "items": {
                  "type": "object",
                  "required": ["key", "names", "value"],
                  "properties": {
                    "key": {
                      "type": "string",
                      "pattern": "^[a-z][a-z0-9_]{0,39}$"
                    },
                    "names": {
                      "$ref": "#/$defs/texts"
                    },
                    "value": {
                      "type": "string",
                      "pattern": "^#[0-9a-f]{6}$",
                      "description": "sRGB colour"
                    }
                  }
                }
              }
            }
          }
        },
        "moving": {
          "type": "array",
          "description": "Parts that open and close: doors, flaps, drawers, sliding panels. node is the name of a node in every model of the element; its origin is the hinge or the point it slides from, and the model shows it closed. open is how far it moves when fully open, in degrees for swing and tilt (a turn about axis, right-handed) and in metres for slide and lift (along axis).",
          "maxItems": 12,
          "items": {
            "type": "object",
            "required": ["node", "names", "motion", "axis", "open"],
            "properties": {
              "node": { "type": "string", "pattern": "^[a-z][a-z0-9_]{0,39}$" },
              "names": { "$ref": "#/$defs/texts" },
              "motion": { "enum": ["swing", "tilt", "slide", "lift"] },
              "axis": { "enum": ["x", "y", "z"] },
              "open": { "type": "number", "minimum": -180, "maximum": 180, "not": { "const": 0 } }
            }
          }
        },
        "optional": {
          "type": "array",
          "description": "Parts people switch on or off, e.g. the backrest of a stool. node is the name of a node in every model of the element; on says whether it is shown when the element is placed.",
          "maxItems": 8,
          "items": {
            "type": "object",
            "required": ["node", "names", "on"],
            "properties": {
              "node": { "type": "string", "pattern": "^[a-z][a-z0-9_]{0,39}$" },
              "names": { "$ref": "#/$defs/texts" },
              "on": { "type": "boolean" }
            }
          }
        },
        "scanCategories": {
          "type": "array",
          "items": {
            "enum": [
              "bathtub",
              "bed",
              "chair",
              "dishwasher",
              "fireplace",
              "oven",
              "refrigerator",
              "sink",
              "sofa",
              "stairs",
              "storage",
              "stove",
              "table",
              "television",
              "toilet",
              "washerDryer"
            ]
          }
        },
        "licence": {
          "enum": ["CC0-1.0", "CC-BY-4.0", "CC-BY-3.0"]
        },
        "attribution": {
          "type": "string",
          "maxLength": 300
        },
        "products": {
          "type": "array",
          "description": "GTIN/EAN numbers this element stands for (#46).",
          "items": {
            "type": "string",
            "pattern": "^\\d{8}(\\d{4,6})?$"
          }
        }
      }
    }
  }
}
