{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.kiduna.ai/coherence/coherence-profile.schema.json",
  "title": "Coherence Profile",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "id", "version", "subject", "scope", "purpose", "status", "dimensions", "principles", "values", "preferences", "constraints", "policyRefs", "authority", "consent", "visibility", "activatedAt", "provenance"],
  "properties": {
    "schemaVersion": { "const": "1.0.0" },
    "id": { "$ref": "coherence-common.schema.json#/$defs/Id" },
    "version": { "$ref": "coherence-common.schema.json#/$defs/Version" },
    "subject": { "$ref": "coherence-common.schema.json#/$defs/EntityRef" },
    "scope": { "$ref": "coherence-common.schema.json#/$defs/ScopeRef" },
    "purpose": { "type": "string", "minLength": 10, "maxLength": 1000 },
    "status": { "enum": ["draft", "rehearsal", "published", "superseded", "retired"] },
    "dimensions": { "type": "array", "items": { "$ref": "#/$defs/DimensionTarget" } },
    "principles": { "type": "array", "items": { "$ref": "#/$defs/Statement" } },
    "values": { "type": "array", "items": { "$ref": "#/$defs/Statement" } },
    "preferences": { "type": "array", "items": { "$ref": "#/$defs/Statement" } },
    "constraints": { "type": "array", "items": { "$ref": "#/$defs/Constraint" } },
    "policyRefs": { "type": "array", "minItems": 1, "items": { "$ref": "coherence-common.schema.json#/$defs/Id" }, "uniqueItems": true },
    "authority": { "$ref": "coherence-common.schema.json#/$defs/Authority" },
    "consent": { "$ref": "coherence-common.schema.json#/$defs/Consent" },
    "visibility": { "$ref": "coherence-common.schema.json#/$defs/Visibility" },
    "activatedAt": { "$ref": "coherence-common.schema.json#/$defs/Timestamp" },
    "expiresAt": { "$ref": "coherence-common.schema.json#/$defs/Timestamp" },
    "provenance": { "$ref": "coherence-common.schema.json#/$defs/Provenance" }
  },
  "$defs": {
    "DimensionTarget": {
      "type": "object",
      "additionalProperties": false,
      "required": ["dimensionRef", "scaleRef", "target", "tolerance", "zones", "boundaryRefs", "inheritanceMode"],
      "properties": {
        "dimensionRef": { "$ref": "coherence-common.schema.json#/$defs/Id" },
        "scaleRef": { "$ref": "coherence-common.schema.json#/$defs/Id" },
        "target": { "$ref": "coherence-common.schema.json#/$defs/Score" },
        "tolerance": {
          "type": "object",
          "additionalProperties": false,
          "required": ["lower", "upper"],
          "properties": { "lower": { "$ref": "coherence-common.schema.json#/$defs/Score" }, "upper": { "$ref": "coherence-common.schema.json#/$defs/Score" } }
        },
        "zones": {
          "type": "array",
          "minItems": 4,
          "items": { "$ref": "#/$defs/Zone" }
        },
        "boundaryRefs": { "type": "array", "items": { "$ref": "coherence-common.schema.json#/$defs/Id" }, "uniqueItems": true },
        "inheritanceMode": { "enum": ["inherit", "override-if-authorized", "locked"] }
      }
    },
    "Zone": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "maxBandDrift", "minimumConfidence", "allowedResponses"],
      "properties": {
        "name": { "enum": ["notice", "warning", "intervention", "escalation"] },
        "maxBandDrift": { "type": ["number", "null"], "exclusiveMinimum": 0 },
        "minimumConfidence": { "$ref": "coherence-common.schema.json#/$defs/Confidence" },
        "allowedResponses": { "type": "array", "minItems": 1, "items": { "$ref": "coherence-common.schema.json#/$defs/ResponseType" }, "uniqueItems": true }
      }
    },
    "Statement": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "text", "priority"],
      "properties": {
        "id": { "$ref": "coherence-common.schema.json#/$defs/Id" },
        "text": { "type": "string", "minLength": 5, "maxLength": 1000 },
        "priority": { "type": "integer", "minimum": 0, "maximum": 1000 }
      }
    },
    "Constraint": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "text", "priority", "predicate", "onViolation"],
      "properties": {
        "id": { "$ref": "coherence-common.schema.json#/$defs/Id" },
        "text": { "type": "string", "minLength": 5, "maxLength": 1000 },
        "priority": { "type": "integer", "minimum": 0, "maximum": 1000 },
        "predicate": { "type": "string", "minLength": 3, "maxLength": 1000 },
        "onViolation": { "enum": ["deny", "pause", "quarantine", "escalate"] }
      }
    }
  }
}
