{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://alxprotocol.com/protocol/1/schemas/error-code-registry.schema.json",
  "title": "ALX Error Code Registry",
  "description": "Schema for core and extension error code registries.",
  "$comment": "Core and extension registries use distinct immutable identifiers and this shared structural schema.",
  "type": "object",
  "required": ["$schema", "$id", "id", "documentVersion", "codes"],
  "additionalProperties": false,
  "properties": {
    "$schema": {
      "const": "https://alxprotocol.com/protocol/1/schemas/error-code-registry.schema.json"
    },
    "$id": {
      "type": "string",
      "pattern": "^https://xandrlabs\\.github\\.io/alx-protocol/protocol/1/(?:error-codes\\.json|extensions/[a-z0-9-]+/error-codes\\.json)$"
    },
    "id": {
      "type": "string",
      "minLength": 1
    },
    "protocolVersion": {
      "type": "string",
      "minLength": 1
    },
    "extensionId": {
      "type": "string",
      "minLength": 1
    },
    "extensionVersion": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
    },
    "documentVersion": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
    },
    "codes": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["id", "code", "category", "severity"],
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^(?:ERR|[A-Z]+ERR)-[0-9]{3}$"
          },
          "code": {
            "type": "string",
            "pattern": "^ALX_[A-Z0-9_]+$"
          },
          "category": {
            "type": "string",
            "minLength": 1
          },
          "severity": {
            "enum": ["fatal", "error", "warning"]
          },
          "description": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "extensionRegistries": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["extensionId", "path"],
        "additionalProperties": false,
        "properties": {
          "extensionId": {
            "type": "string",
            "minLength": 1
          },
          "path": {
            "type": "string",
            "minLength": 1
          },
          "note": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    }
  },
  "oneOf": [
    {
      "required": ["protocolVersion", "extensionRegistries"],
      "not": {
        "anyOf": [
          { "required": ["extensionId"] },
          { "required": ["extensionVersion"] }
        ]
      }
    },
    {
      "required": ["extensionId", "extensionVersion"],
      "not": {
        "anyOf": [
          { "required": ["protocolVersion"] },
          { "required": ["extensionRegistries"] }
        ]
      }
    }
  ]
}
