{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openeik.org/schemas/0.8/checks/check.schema.json",
  "$comment": "OpenEik 0.7: folded by tools/fold-schemas-0.7.mjs from the proposal checks, which 0.7 makes a rule (open questions, 169). Written by hand, not generated.",
  "title": "A check",
  "description": "A test of a building (Part XXIII, 4): the sentence a person said, the rule it compiles to, and two small buildings that prove the rule means the sentence, one that passes and one that fails.",
  "type": "object",
  "required": [
    "format",
    "id",
    "version",
    "says",
    "severity",
    "source",
    "requires",
    "fixtures"
  ],
  "additionalProperties": false,
  "properties": {
    "format": {
      "const": "openeik-check/0.1"
    },
    "id": {
      "description": "The check's id, its file's name without .json (rule 1).",
      "$ref": "#/$defs/name"
    },
    "version": {
      "description": "Its version, raised whenever what it requires changes, so that a waiver of an earlier version no longer applies (rule 2).",
      "type": "integer",
      "minimum": 1,
      "maximum": 1000000
    },
    "says": {
      "description": "The sentence, as the person said it, in the language of the suite (rule 3).",
      "type": "string",
      "minLength": 1,
      "maxLength": 1000
    },
    "severity": {
      "description": "What a failure is: an error, a warning or an info (rule 4).",
      "enum": [
        "error",
        "warning",
        "info"
      ]
    },
    "source": {
      "$ref": "#/$defs/source"
    },
    "params": {
      "description": "The values it takes, each by its name (rule 6).",
      "type": "object",
      "maxProperties": 20,
      "propertyNames": {
        "$ref": "#/$defs/paramName"
      },
      "additionalProperties": {
        "$ref": "#/$defs/param"
      }
    },
    "when": {
      "description": "When it is run (rule 7): only where each parameter of params is given, and, with since, only where the day the project's application reached the authority, its permit's applied (Part II, 2.5), is the day its rules apply from or later, or where the project's permit chose them before it.",
      "type": "object",
      "minProperties": 1,
      "additionalProperties": false,
      "properties": {
        "params": {
          "type": "array",
          "minItems": 1,
          "maxItems": 20,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/paramName"
          }
        },
        "since": {
          "description": "The rules it checks apply to a project by the day its application reached the authority, its permit's applied (Part II, 2.5; rule 7): from day, and before it where the project's permit chose them by their name, newRules[rules] true; else it is not run, and says what the project applies in their place (before).",
          "type": "object",
          "required": [
            "day",
            "before"
          ],
          "additionalProperties": false,
          "properties": {
            "day": {
              "description": "The first day of application the rules apply to a project from, YYYY-MM-DD.",
              "type": "string",
              "pattern": "^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$"
            },
            "rules": {
              "description": "The rules' name, by which a project's permit gives its choice where a transition lets a project that applied before day choose them (Part II, 2.5, rule 2): BFS 2024:6-13.",
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            },
            "before": {
              "description": "What a project applies in their place before day, naming the rules by their numbers.",
              "type": "string",
              "minLength": 1,
              "maxLength": 500
            }
          }
        }
      }
    },
    "needs": {
      "description": "What the model holds where the check can be run at all: one of these selects an element, else the check is skipped, and says why (rule 7).",
      "type": "object",
      "required": [
        "any",
        "says"
      ],
      "additionalProperties": false,
      "properties": {
        "any": {
          "type": "array",
          "minItems": 1,
          "maxItems": 10,
          "items": {
            "$ref": "#/$defs/selector"
          }
        },
        "says": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        }
      }
    },
    "applies": {
      "description": "The elements it applies to (rule 5). An analysis check applies to result sets, and gives none.",
      "$ref": "#/$defs/selector"
    },
    "requires": {
      "description": "What each element it applies to must hold: one rule of a kind of Part XXIII, 6 (rule 5).",
      "$ref": "#/$defs/rule"
    },
    "fix": {
      "description": "What a person does about a failure, in a sentence.",
      "type": "string",
      "minLength": 1,
      "maxLength": 1000
    },
    "fixtures": {
      "description": "The small buildings that prove it, each a model in the single-file form at its path in the folder tests/<id>/ of its suite (rule 9).",
      "type": "object",
      "required": [
        "pass",
        "fail"
      ],
      "additionalProperties": false,
      "properties": {
        "pass": {
          "type": "array",
          "minItems": 1,
          "maxItems": 20,
          "items": {
            "$ref": "#/$defs/fixture"
          }
        },
        "fail": {
          "type": "array",
          "minItems": 1,
          "maxItems": 20,
          "items": {
            "$ref": "#/$defs/fixture"
          }
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "requires": {
            "properties": {
              "kind": {
                "const": "analysis"
              }
            },
            "required": [
              "kind"
            ]
          }
        },
        "required": [
          "requires"
        ]
      },
      "then": {
        "not": {
          "required": [
            "applies"
          ]
        }
      },
      "else": {
        "required": [
          "applies"
        ]
      }
    }
  ],
  "$defs": {
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 64,
      "pattern": "^[a-z][a-z0-9]*(-[a-z0-9]+)*$"
    },
    "paramName": {
      "type": "string",
      "minLength": 1,
      "maxLength": 40,
      "pattern": "^[a-z][A-Za-z0-9]*$"
    },
    "path": {
      "description": "A member of an element, its names joined by dots (offset, mep.size); of its type after type. (type.room.use); a derived value, @system, @flow, @thickness, @downpipe, @unit or @unitLevels; or a member of the room on a door's or a window's left or right, after @left. or @right. (@left.room.unit), or that room's id, @left or @right (Part XXIII, 5, rule 3).",
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "pattern": "^(@(system|flow|thickness|downpipe|unit|unitLevels|clearWidth|clearHeight)|@(left|right)(\\.(type\\.)?[A-Za-z][A-Za-z0-9]*(\\.[A-Za-z][A-Za-z0-9]*){0,7})?|(type\\.)?[A-Za-z][A-Za-z0-9]*(\\.[A-Za-z][A-Za-z0-9]*){0,7})$"
    },
    "scalar": {
      "type": [
        "string",
        "number",
        "boolean",
        "null"
      ]
    },
    "param": {
      "type": "object",
      "required": [
        "type",
        "says"
      ],
      "additionalProperties": false,
      "properties": {
        "type": {
          "enum": [
            "number",
            "string",
            "boolean",
            "list",
            "table"
          ]
        },
        "says": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "unit": {
          "type": "string",
          "minLength": 1,
          "maxLength": 20
        },
        "min": {
          "type": "number"
        },
        "max": {
          "type": "number"
        },
        "default": {},
        "tighter": {
          "description": "Which way a layer above may change it: lower, higher or more (a list with more items); without it, a layer gives it only where no layer below gave it (Part XXIII, 3, rule 4).",
          "enum": [
            "lower",
            "higher",
            "more"
          ]
        }
      }
    },
    "value": {
      "description": "A value: given, or a parameter's by its name.",
      "oneOf": [
        {
          "$ref": "#/$defs/scalar"
        },
        {
          "type": "array",
          "maxItems": 1000,
          "items": {
            "$ref": "#/$defs/scalar"
          }
        },
        {
          "type": "object",
          "required": [
            "param"
          ],
          "additionalProperties": false,
          "properties": {
            "param": {
              "$ref": "#/$defs/paramName"
            }
          }
        }
      ]
    },
    "condition": {
      "description": "What a value of a member must be: a scalar it equals, or a test.",
      "oneOf": [
        {
          "$ref": "#/$defs/scalar"
        },
        {
          "type": "object",
          "minProperties": 1,
          "additionalProperties": false,
          "properties": {
            "equals": {
              "$ref": "#/$defs/value"
            },
            "in": {
              "$ref": "#/$defs/value"
            },
            "notIn": {
              "$ref": "#/$defs/value"
            },
            "present": {
              "type": "boolean"
            },
            "min": {
              "$ref": "#/$defs/value"
            },
            "max": {
              "$ref": "#/$defs/value"
            }
          }
        }
      ]
    },
    "where": {
      "type": "object",
      "minProperties": 1,
      "maxProperties": 10,
      "propertyNames": {
        "$ref": "#/$defs/path"
      },
      "additionalProperties": {
        "$ref": "#/$defs/condition"
      }
    },
    "selector": {
      "description": "Which elements: of these categories, whose members hold these conditions, that hold such an element (a room), and of which one of anyOf holds (Part XXIII, 5).",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "category": {
          "oneOf": [
            {
              "type": "string",
              "pattern": "^[a-z][A-Za-z0-9]*$",
              "maxLength": 32
            },
            {
              "type": "array",
              "minItems": 1,
              "maxItems": 40,
              "uniqueItems": true,
              "items": {
                "type": "string",
                "pattern": "^[a-z][A-Za-z0-9]*$",
                "maxLength": 32
              }
            }
          ]
        },
        "where": {
          "$ref": "#/$defs/where"
        },
        "contains": {
          "$ref": "#/$defs/selector"
        },
        "anyOf": {
          "type": "array",
          "minItems": 1,
          "maxItems": 10,
          "items": {
            "$ref": "#/$defs/selector"
          }
        }
      }
    },
    "expression": {
      "description": "A number: given, a parameter's, a measure of the element (Part XXIII, 7), a product, the largest or the smallest of several, one less another, or a sum of a measure over related elements (Part XXIII, 6.4).",
      "oneOf": [
        {
          "type": "number"
        },
        {
          "type": "object",
          "required": [
            "param"
          ],
          "additionalProperties": false,
          "properties": {
            "param": {
              "$ref": "#/$defs/paramName"
            }
          }
        },
        {
          "type": "object",
          "required": [
            "measure"
          ],
          "additionalProperties": false,
          "properties": {
            "measure": {
              "enum": [
                "flow",
                "catchmentArea",
                "drainCapacity",
                "netFloorArea",
                "clearWidth",
                "clearHeight"
              ]
            },
            "gutters": {
              "$ref": "#/$defs/value"
            },
            "downpipes": {
              "$ref": "#/$defs/value"
            }
          }
        },
        {
          "type": "object",
          "required": [
            "product"
          ],
          "additionalProperties": false,
          "properties": {
            "product": {
              "type": "array",
              "minItems": 2,
              "maxItems": 10,
              "items": {
                "$ref": "#/$defs/expression"
              }
            }
          }
        },
        {
          "type": "object",
          "required": [
            "max"
          ],
          "additionalProperties": false,
          "properties": {
            "max": {
              "description": "The largest of the expressions.",
              "type": "array",
              "minItems": 2,
              "maxItems": 10,
              "items": {
                "$ref": "#/$defs/expression"
              }
            }
          }
        },
        {
          "type": "object",
          "required": [
            "min"
          ],
          "additionalProperties": false,
          "properties": {
            "min": {
              "description": "The smallest of the expressions.",
              "type": "array",
              "minItems": 2,
              "maxItems": 10,
              "items": {
                "$ref": "#/$defs/expression"
              }
            }
          }
        },
        {
          "type": "object",
          "required": [
            "difference"
          ],
          "additionalProperties": false,
          "properties": {
            "difference": {
              "description": "The first expression less the second.",
              "type": "array",
              "minItems": 2,
              "maxItems": 2,
              "items": {
                "$ref": "#/$defs/expression"
              }
            }
          }
        },
        {
          "type": "object",
          "required": [
            "sum"
          ],
          "additionalProperties": false,
          "properties": {
            "sum": {
              "description": "A sum of a measure over the elements related to the element by one relation (relation and to), or reached from it by a path of relations, each step from the elements the step before reached (path).",
              "oneOf": [
                {
                  "type": "object",
                  "required": [
                    "relation",
                    "to",
                    "measure"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "relation": {
                      "$ref": "#/$defs/relation"
                    },
                    "to": {
                      "$ref": "#/$defs/selector"
                    },
                    "measure": {
                      "$ref": "#/$defs/summed"
                    }
                  }
                },
                {
                  "type": "object",
                  "required": [
                    "path",
                    "measure"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "path": {
                      "type": "array",
                      "minItems": 1,
                      "maxItems": 5,
                      "items": {
                        "type": "object",
                        "required": [
                          "relation",
                          "to"
                        ],
                        "additionalProperties": false,
                        "properties": {
                          "relation": {
                            "$ref": "#/$defs/relation"
                          },
                          "to": {
                            "$ref": "#/$defs/selector"
                          }
                        }
                      }
                    },
                    "measure": {
                      "$ref": "#/$defs/summed"
                    }
                  }
                }
              ]
            }
          }
        }
      ]
    },
    "relation": {
      "$ref": "../roomWayIn/relation.schema.json"
    },
    "summed": {
      "description": "A measure a sum adds up over elements (Part XXIII, 6.4).",
      "enum": [
        "flow",
        "catchmentArea",
        "netFloorArea",
        "clearWidth",
        "clearHeight"
      ]
    },
    "limitKinds": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "enum": [
          "facadeLine",
          "buildingLimit",
          "noBuild",
          "heightLimit"
        ]
      }
    },
    "rule": {
      "type": "object",
      "required": [
        "kind"
      ],
      "properties": {
        "kind": {
          "enum": [
            "property",
            "relation",
            "geometry",
            "quantity",
            "analysis",
            "outside"
          ]
        }
      },
      "oneOf": [
        {
          "description": "property (5.1): a member present, or a value in range.",
          "type": "object",
          "required": [
            "kind",
            "member"
          ],
          "additionalProperties": false,
          "properties": {
            "kind": {
              "const": "property"
            },
            "member": {
              "$ref": "#/$defs/path"
            },
            "present": {
              "const": true
            },
            "equals": {
              "$ref": "#/$defs/value"
            },
            "in": {
              "$ref": "#/$defs/value"
            },
            "notIn": {
              "$ref": "#/$defs/value"
            },
            "min": {
              "$ref": "#/$defs/value"
            },
            "max": {
              "$ref": "#/$defs/value"
            },
            "unit": {
              "type": "string",
              "minLength": 1,
              "maxLength": 20
            }
          }
        },
        {
          "description": "relation (5.2): a path of relations from the element, each step reaching an element of its selector.",
          "type": "object",
          "required": [
            "kind",
            "path"
          ],
          "additionalProperties": false,
          "properties": {
            "kind": {
              "const": "relation"
            },
            "path": {
              "type": "array",
              "minItems": 1,
              "maxItems": 5,
              "items": {
                "type": "object",
                "required": [
                  "relation",
                  "to",
                  "says"
                ],
                "additionalProperties": false,
                "properties": {
                  "relation": {
                    "$ref": "#/$defs/relation"
                  },
                  "to": {
                    "$ref": "#/$defs/selector"
                  },
                  "says": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 300
                  }
                }
              }
            }
          }
        },
        {
          "description": "geometry (5.3): the element's footprint against a plan's limits, within a tolerance.",
          "type": "object",
          "required": [
            "kind"
          ],
          "additionalProperties": false,
          "anyOf": [
            {
              "required": [
                "inside"
              ]
            },
            {
              "required": [
                "outside"
              ]
            },
            {
              "required": [
                "behind"
              ]
            }
          ],
          "properties": {
            "kind": {
              "const": "geometry"
            },
            "inside": {
              "$ref": "#/$defs/limitKinds"
            },
            "outside": {
              "$ref": "#/$defs/limitKinds"
            },
            "behind": {
              "$ref": "#/$defs/limitKinds"
            },
            "tolerance": {
              "$ref": "#/$defs/expression"
            },
            "footprint": {
              "$ref": "../footprintsWhole/footprint.schema.json"
            }
          }
        },
        {
          "description": "quantity (5.4): a number of the element against a bound.",
          "type": "object",
          "required": [
            "kind",
            "value"
          ],
          "additionalProperties": false,
          "anyOf": [
            {
              "required": [
                "atMost"
              ]
            },
            {
              "required": [
                "atLeast"
              ]
            }
          ],
          "properties": {
            "kind": {
              "const": "quantity"
            },
            "value": {
              "$ref": "#/$defs/expression"
            },
            "atMost": {
              "$ref": "#/$defs/expression"
            },
            "atLeast": {
              "$ref": "#/$defs/expression"
            },
            "unit": {
              "type": "string",
              "minLength": 1,
              "maxLength": 20
            }
          }
        },
        {
          "description": "analysis (5.5): a value an application's result set holds, current by its inputs.",
          "type": "object",
          "required": [
            "kind",
            "result",
            "value"
          ],
          "additionalProperties": false,
          "anyOf": [
            {
              "required": [
                "atMost"
              ]
            },
            {
              "required": [
                "atLeast"
              ]
            }
          ],
          "properties": {
            "kind": {
              "const": "analysis"
            },
            "result": {
              "type": "object",
              "required": [
                "kind"
              ],
              "additionalProperties": false,
              "properties": {
                "kind": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100
                },
                "app": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100
                }
              }
            },
            "value": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200,
              "pattern": "^[A-Za-z][A-Za-z0-9]*(\\.[A-Za-z][A-Za-z0-9]*){0,7}$"
            },
            "atMost": {
              "$ref": "#/$defs/expression"
            },
            "atLeast": {
              "$ref": "#/$defs/expression"
            },
            "unit": {
              "type": "string",
              "minLength": 1,
              "maxLength": 20
            }
          }
        },
        {
          "description": "outside (5.6): the element against a supplied list.",
          "type": "object",
          "required": [
            "kind",
            "list",
            "match"
          ],
          "additionalProperties": false,
          "properties": {
            "kind": {
              "const": "outside"
            },
            "list": {
              "type": "object",
              "required": [
                "param"
              ],
              "additionalProperties": false,
              "properties": {
                "param": {
                  "$ref": "#/$defs/paramName"
                }
              }
            },
            "match": {
              "type": "object",
              "minProperties": 1,
              "maxProperties": 10,
              "propertyNames": {
                "$ref": "#/$defs/path"
              },
              "additionalProperties": {
                "type": "string",
                "minLength": 1,
                "maxLength": 80
              }
            },
            "count": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            }
          }
        }
      ]
    },
    "source": {
      "description": "Where the requirement comes from (rule 8): practice, the client, or a public rule named by its publisher, its document and its paragraph, never by its text.",
      "type": "object",
      "required": [
        "kind"
      ],
      "additionalProperties": false,
      "properties": {
        "kind": {
          "enum": [
            "practice",
            "client",
            "rule"
          ]
        },
        "publisher": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "document": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "paragraph": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "note": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        }
      },
      "if": {
        "properties": {
          "kind": {
            "const": "rule"
          }
        }
      },
      "then": {
        "required": [
          "publisher",
          "document",
          "paragraph"
        ]
      }
    },
    "fixture": {
      "oneOf": [
        {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9-]*\\.json$",
          "maxLength": 100
        },
        {
          "type": "object",
          "required": [
            "model"
          ],
          "additionalProperties": false,
          "properties": {
            "model": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9-]*\\.json$",
              "maxLength": 100
            },
            "params": {
              "type": "object",
              "maxProperties": 20,
              "propertyNames": {
                "$ref": "#/$defs/paramName"
              }
            },
            "elements": {
              "description": "Of a failing fixture, exactly the elements that fail, by their ids.",
              "type": "array",
              "minItems": 1,
              "maxItems": 100,
              "uniqueItems": true,
              "items": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        }
      ]
    }
  }
}
