{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.com/tpso.schema.json",
  "title": "TPSO Mapping",
  "type": "object",
  "required": ["meta", "tpso", "codesTree", "zones", "codes", "crosswalk"],
  "properties": {
    "meta": {
      "type": "object",
      "required": ["version", "source"],
      "properties": {
        "version": { "type": "string" },
        "source": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["title", "url"],
            "properties": {
              "title": { "type": "string" },
              "url": { "type": "string", "format": "uri" }
            },
            "additionalProperties": false
          }
        },
        "notes": { "type": "string" }
      },
      "additionalProperties": true
    },
    "tpso": {
      "type": "object",
      "required": ["base", "effectiveForDate", "map"],
      "properties": {
        "base": { "type": "string", "format": "uri" },
        "effectiveForDate": { "type": "string" },
        "map": {
          "type": "object",
          "patternProperties": {
            "^(ADMINISTRATION_INDEX|GENERAL-PROVISIONS_INDEX|ZONES_INDEX|CODES_INDEX|([0-9]+(\\.[0-9]+)*))$": {
              "type": "integer",
              "minimum": 0
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "codesTree": {
      "type": "array",
      "items": { "$ref": "#/$defs/CodeNode" }
    },
    "zones": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "doc_section", "key_clauses"],
        "properties": {
          "name": { "type": "string" },
          "doc_section": { "type": "string", "pattern": "^[0-9]+(\\.[0-9]+)*$" },
          "key_clauses": {
            "type": "object",
            "properties": {
              "purpose": { "type": "string" },
              "use_table": { "type": "string" },
              "use_standards": { "type": "string" },
              "dev_standards_dwellings": { "type": "string" },
              "dev_standards_non_dwellings": { "type": "string" },
              "dev_standards_buildings_works": { "type": "string" },
              "subdivision": { "type": "string" }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      }
    },
    "codes": {
      "type": "object",
      "patternProperties": {
        "^C[0-9]+$": {
          "type": "object",
          "properties": {
            "key_clauses": { "$ref": "#/$defs/KeyClauses" }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "crosswalk": {
      "type": "object",
      "properties": {
        "aliases": {
          "type": "object",
          "patternProperties": {
            "^[a-z0-9_]+$": { "type": "string", "pattern": "^C[0-9]+$" }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    }
  },
  "$defs": {
    "CodeNode": {
      "type": "object",
      "required": ["id", "title"],
      "properties": {
        "id": { "type": "integer" },
        "title": { "type": "string" },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/CodeNode" }
        }
      },
      "additionalProperties": false
    },
    "KeyClauses": {
      "type": "object",
      "properties": {
        "purpose": { "type": "string" },
        "application": { "type": "string" },
        "definitions": { "type": "string" },
        "exempt": { "type": "string" },
        "use_standards": { "type": "string" },
        "use_standards_detail": {
          "type": "array",
          "items": { "$ref": "#/$defs/ClauseDetail" }
        },
        "development_standards": { "type": "string" },
        "development_standards_detail": {
          "type": "array",
          "items": { "$ref": "#/$defs/ClauseDetail" }
        }
      },
      "additionalProperties": false
    },
    "ClauseDetail": {
      "type": "object",
      "required": ["id", "title"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Z][0-9]+(\\.[0-9]+)*$" },
        "title": { "type": "string" }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
