{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rootandbranchregister.org/schema/trade-register-0.1.json",
  "title": "Root & Branch Trade Register",
  "description": "The authority file of trade terms. A Practice Record, Transmission Record or Entry names a trade by term id, never by free text.",
  "type": "object",
  "required": [
    "trade_register_version",
    "as_of",
    "terms"
  ],
  "properties": {
    "trade_register_version": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+$"
    },
    "as_of": {
      "type": "string",
      "format": "date"
    },
    "license": {
      "type": "string"
    },
    "governing_standard": {
      "type": "string"
    },
    "term_count": {
      "type": "integer",
      "minimum": 0
    },
    "groups": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "label"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-z0-9-]+$"
          },
          "label": {
            "type": "string",
            "minLength": 1
          }
        },
        "additionalProperties": false
      }
    },
    "terms": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/term"
      }
    },
    "supersedes": {
      "type": "string"
    }
  },
  "$defs": {
    "term": {
      "type": "object",
      "required": [
        "id",
        "preferred_label",
        "group",
        "soc_code",
        "status",
        "in_scope"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^TR-[0-9]{5}$",
          "description": "Permanent. Never reassigned, never deleted; a merged term keeps its id and points at its successor."
        },
        "preferred_label": {
          "type": "string",
          "minLength": 2
        },
        "slug": {
          "type": "string",
          "pattern": "^[a-z0-9-]+$"
        },
        "variant_labels": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 2
          },
          "description": "Lowercased alternate spellings and trade names that resolve to this term. Type-ahead matches these as well as the preferred label."
        },
        "group": {
          "type": "string",
          "pattern": "^[a-z0-9-]+$"
        },
        "group_label": {
          "type": "string"
        },
        "soc_code": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[0-9]{2}-[0-9]{4}$",
          "description": "Federal occupation code, or null. Null is a finding, not missing data, and requires soc_absent_reason."
        },
        "soc_absent_reason": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 10
        },
        "in_scope": {
          "type": "boolean",
          "description": "False for a term the assessment measures but the Standard does not enroll."
        },
        "out_of_scope_reason": {
          "type": "string",
          "minLength": 10
        },
        "status": {
          "enum": [
            "current",
            "variant_of",
            "proposed",
            "rejected"
          ]
        },
        "variant_of": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^TR-[0-9]{5}$",
          "description": "Set when status is variant_of. The superseded id keeps resolving, so citations never break."
        },
        "rejection_reason": {
          "type": "string",
          "minLength": 10
        },
        "proposed_by": {
          "type": "string"
        },
        "proposed_on": {
          "type": "string",
          "format": "date"
        },
        "risk_assessment": {
          "type": "string"
        },
        "first_published": {
          "type": "string",
          "format": "date"
        },
        "sources": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "note": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "soc_code": {
                "const": null
              }
            }
          },
          "then": {
            "required": [
              "soc_absent_reason"
            ],
            "properties": {
              "soc_absent_reason": {
                "type": "string"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "status": {
                "const": "variant_of"
              }
            }
          },
          "then": {
            "required": [
              "variant_of"
            ],
            "properties": {
              "variant_of": {
                "type": "string"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "status": {
                "const": "rejected"
              }
            }
          },
          "then": {
            "required": [
              "rejection_reason"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "in_scope": {
                "const": false
              }
            }
          },
          "then": {
            "required": [
              "out_of_scope_reason"
            ]
          }
        }
      ]
    }
  },
  "additionalProperties": false
}