{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tylereno.me/cel/schemas/incident_taxonomy.json",
  "title": "CelIncidentTaxonomy",
  "description": "Speakable CEL incident catalog. Finite and mission-scoped. HIP/CAP/GLIDE identifiers are optional profiles, never the primary code.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "version",
    "cel_spec",
    "title",
    "namespace",
    "root",
    "codes"
  ],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^cel\\.taxonomy\\.[a-z][a-z0-9_]*$",
      "description": "Stable catalog identifier."
    },
    "version": {
      "type": "string",
      "minLength": 1
    },
    "cel_spec": {
      "type": "string",
      "const": "0.1.0"
    },
    "title": { "type": "string", "minLength": 1 },
    "description": { "type": "string" },
    "namespace": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]*$"
    },
    "root": {
      "type": "string",
      "minLength": 1
    },
    "codes": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/incidentCode" }
    }
  },
  "$defs": {
    "profiles": {
      "type": "object",
      "additionalProperties": false,
      "description": "Foreign identifiers. Never used as the CEL code.",
      "properties": {
        "undrr_hip": {
          "type": "string",
          "pattern": "^[A-Z]{2}[0-9]{4}$"
        },
        "glide": {
          "type": "string",
          "pattern": "^[A-Z]{2}$"
        },
        "cap_event": { "type": "string", "minLength": 1 },
        "cap_category": { "type": "string", "minLength": 1 }
      }
    },
    "incidentCode": {
      "type": "object",
      "additionalProperties": false,
      "required": ["code", "label", "spoken", "kind"],
      "properties": {
        "code": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)*$",
          "description": "Speakable dotted CEL word, for example disaster.fire.wildland."
        },
        "label": { "type": "string", "minLength": 1 },
        "spoken": {
          "type": "string",
          "minLength": 1,
          "description": "The same word with dots turned into spaces."
        },
        "kind": {
          "type": "string",
          "enum": ["root", "category", "leaf"]
        },
        "parent": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)*$"
        },
        "children": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)*$"
          },
          "uniqueItems": true
        },
        "description": { "type": "string" },
        "notes": {
          "type": "array",
          "items": { "type": "string" }
        },
        "profiles": { "$ref": "#/$defs/profiles" }
      },
      "allOf": [
        {
          "if": { "properties": { "kind": { "const": "root" } }, "required": ["kind"] },
          "then": { "not": { "required": ["parent"] } },
          "else": { "required": ["parent"] }
        }
      ]
    }
  }
}
