{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://paloframework.org/schemas/palo-semantic-mapping-registry.schema.json",
  "title": "PALO Atomic Semantic Mapping Registry",
  "type": "object",
  "required": ["format", "schemaVersion", "semanticVersion", "releasedAt", "status", "authorityBoundary", "mappings"],
  "properties": {
    "format": { "const": "palo-semantic-mapping-registry" },
    "schemaVersion": { "const": "1.0.0" },
    "semanticVersion": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$" },
    "releasedAt": { "type": "string", "format": "date" },
    "status": { "enum": ["draft", "in-review", "approved-for-release", "deprecated", "superseded"] },
    "authorityBoundary": { "type": "string", "minLength": 1 },
    "mappings": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["mappingId", "mappingVersion", "mappingType", "source", "target", "coverageType", "conditions", "rationale", "basis", "approval", "validFrom", "provenance"],
        "properties": {
          "mappingId": { "type": "string", "format": "uri" },
          "mappingVersion": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$" },
          "mappingType": { "enum": ["control-to-source", "control-to-indicator", "control-to-gate", "indicator-to-source", "indicator-to-gate", "gate-to-source"] },
          "source": { "$ref": "#/$defs/versionedRef" },
          "target": { "$ref": "#/$defs/versionedRef" },
          "coverageType": { "enum": ["total", "partial", "conditional", "supporting"] },
          "conditions": { "type": "array", "items": { "type": "string" } },
          "rationale": { "type": "string", "minLength": 1 },
          "basis": { "type": "string", "minLength": 1 },
          "approval": {
            "type": "object",
            "required": ["status", "scope", "decidedAt", "decidedBy"],
            "properties": {
              "status": { "enum": ["draft", "in-review", "approved", "rejected", "superseded"] },
              "scope": { "type": "string", "minLength": 1 },
              "decidedAt": { "type": "string", "format": "date-time" },
              "decidedBy": { "type": "string", "minLength": 1 }
            },
            "additionalProperties": false
          },
          "validFrom": { "type": "string", "format": "date-time" },
          "validTo": { "type": "string", "format": "date-time" },
          "supersedesMappingId": { "type": "string", "format": "uri" },
          "provenance": {
            "type": "object",
            "required": ["generatedFrom", "generationRule"],
            "properties": {
              "generatedFrom": { "type": "string" },
              "generationRule": { "type": "string" }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      }
    }
  },
  "$defs": {
    "versionedRef": {
      "type": "object",
      "required": ["entityType", "entityId", "semanticId", "version"],
      "properties": {
        "entityType": { "enum": ["control", "indicator", "gate", "source"] },
        "entityId": { "type": "string", "minLength": 1 },
        "semanticId": { "type": "string", "format": "uri" },
        "version": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$" }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
