{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "open-furniture.system40.config/1",
  "title": "System 40 Open Joint design configuration",
  "description": "The input the builder, the agent tools and system/model.js normalize() accept. Millimetres. The model repairs what it can (heights snap to the 40 mm grid, shelves too close together are dropped, a 1200 bay becomes open below) and reports the rest as checks. Rows: a shelf on row n finishes 40 × (n + 1) mm above the foot; the top row of a bay of height h is h / 40 − 1.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "name": {
      "type": "string",
      "maxLength": 60,
      "default": "Untitled"
    },
    "depth": {
      "enum": [
        400,
        600,
        800
      ],
      "default": 400
    },
    "carcass": {
      "enum": [
        "birch",
        "chalk",
        "graphite"
      ],
      "default": "birch"
    },
    "fronts": {
      "enum": [
        "birch",
        "chalk",
        "graphite",
        "oxide",
        "olive",
        "cobalt",
        "signal"
      ],
      "default": "birch"
    },
    "sheet": {
      "enum": [
        "2500x1250",
        "2440x1220"
      ],
      "default": "2500x1250"
    },
    "top": {
      "description": "One continuous top over the whole run, or null. Bays under a top share one height.",
      "oneOf": [
        {
          "type": "null"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "ends": {
              "type": "integer",
              "minimum": 0,
              "maximum": 300,
              "multipleOf": 10,
              "description": "Overhang past each end, mm."
            },
            "front": {
              "type": "integer",
              "minimum": 0,
              "maximum": 100,
              "multipleOf": 10,
              "description": "Overhang at the front, mm."
            },
            "back": {
              "type": "integer",
              "minimum": 0,
              "maximum": 100,
              "multipleOf": 10,
              "description": "Overhang at the back, mm, for a table used from both sides."
            }
          }
        }
      ]
    },
    "bays": {
      "type": "array",
      "minItems": 1,
      "maxItems": 8,
      "items": {
        "$ref": "#/$defs/bay"
      },
      "description": "Left to right."
    }
  },
  "$defs": {
    "bay": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "w",
        "h"
      ],
      "properties": {
        "w": {
          "enum": [
            400,
            600,
            800,
            1200
          ],
          "description": "Bay width, mm: upright centre to upright centre. Shelves span 800 at most, so 1200 bays are open below."
        },
        "h": {
          "type": "integer",
          "minimum": 360,
          "maximum": 2400,
          "multipleOf": 40,
          "description": "Upright height, mm."
        },
        "shelves": {
          "type": "array",
          "items": {
            "type": "integer",
            "minimum": 0
          },
          "description": "Grid rows of the shelves, bottom to top. The first is 0 to 2 (a 32 or 112 mm floor gap); the last is the top row; cells are at least 3 rows (120 mm)."
        },
        "cells": {
          "type": "object",
          "description": "The cell above each shelf except the top one, keyed by that shelf's row.",
          "additionalProperties": {
            "$ref": "#/$defs/cell"
          }
        },
        "knee": {
          "type": "boolean",
          "description": "Open below: no shelves, a spine back under the top."
        },
        "spine": {
          "type": "integer",
          "minimum": 6,
          "maximum": 12,
          "description": "Spine height in grid rows, for an open bay."
        },
        "centre": {
          "type": "boolean",
          "description": "Open bay at the 800 work depth: the spine stands on the centre line."
        },
        "beams": {
          "enum": [
            0,
            1,
            2
          ],
          "description": "Open bay under a top: edge beams, 1 at the front, 2 at front and back (needs centre)."
        },
        "grommet": {
          "type": "boolean",
          "description": "Open bay under a top: a Ø80 cable grommet in the top, in front of the spine."
        }
      }
    },
    "cell": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "front": {
          "enum": [
            "open",
            "door",
            "doors",
            "drawers"
          ],
          "description": "door in 400 and 600 bays, doors (a pair) in 800 bays. Doors need 160 mm on the grid, drawers 102 mm clear."
        },
        "hinge": {
          "enum": [
            "l",
            "r"
          ]
        },
        "n": {
          "type": "integer",
          "minimum": 1,
          "maximum": 4,
          "description": "Drawers, each front 100 mm or more."
        },
        "back": {
          "type": "boolean",
          "description": "The brace. Every bay needs one."
        },
        "rail": {
          "type": "boolean",
          "description": "Clothes rail: 600 depth, 500 mm clear, no drawers."
        },
        "mid": {
          "type": "boolean",
          "description": "The back on the centre line, so the cell opens from both sides: 800 depth, no drawers."
        },
        "lock": {
          "type": "boolean",
          "description": "A cam lock: doors only."
        }
      }
    }
  },
  "examples": [
    {
      "name": "Sideboard",
      "depth": 400,
      "carcass": "birch",
      "fronts": "olive",
      "top": {
        "ends": 0,
        "front": 0
      },
      "bays": [
        {
          "w": 600,
          "h": 720,
          "shelves": [
            2,
            17
          ],
          "cells": {
            "2": {
              "front": "drawers",
              "back": true,
              "n": 3
            }
          }
        },
        {
          "w": 800,
          "h": 720,
          "shelves": [
            2,
            17
          ],
          "cells": {
            "2": {
              "front": "doors",
              "back": true
            }
          }
        },
        {
          "w": 600,
          "h": 720,
          "shelves": [
            2,
            17
          ],
          "cells": {
            "2": {
              "front": "drawers",
              "back": true,
              "n": 3
            }
          }
        }
      ]
    }
  ]
}
