{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://dicworkflowkit.local/schemas/ontology-attestation.schema.json",
  "title": "DIC Ontology Attestation",
  "description": "Content-addressed final decision bound to ontology, ledger, sources, and invariants.",
  "type": "object",
  "required": [
    "schema",
    "attestationId",
    "contentHash",
    "version",
    "status",
    "final",
    "summary",
    "createdAt",
    "snapshot",
    "ledger",
    "sources",
    "evidence",
    "implementations",
    "validationCausality",
    "invariants"
  ],
  "properties": {
    "schema": { "const": "dic.ontology-attestation.v1" },
    "attestationId": {
      "type": "string",
      "pattern": "^att-[a-f0-9]{16}$"
    },
    "contentHash": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "version": { "type": "string" },
    "status": { "enum": ["PASS", "PARTIAL", "BLOCKED", "FAIL"] },
    "final": { "const": true },
    "summary": { "type": "string", "minLength": 1 },
    "createdAt": { "type": "string", "format": "date-time" },
    "snapshot": {
      "type": "object",
      "required": ["snapshotId", "snapshotRevision"],
      "properties": {
        "snapshotId": { "type": "string" },
        "snapshotRevision": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      },
      "additionalProperties": false
    },
    "ledger": {
      "type": "object",
      "required": ["sha256", "actionCount", "headHash"],
      "properties": {
        "sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "actionCount": { "type": "integer", "minimum": 0 },
        "headHash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      },
      "additionalProperties": false
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "path", "status", "contentHash"],
        "properties": {
          "id": { "type": "string" },
          "path": { "type": "string" },
          "status": {
            "enum": [
              "UNCHANGED",
              "CHANGED",
              "MISSING",
              "UNTRACKED",
              "OUTSIDE_PROJECT",
              "INVALID"
            ]
          },
          "contentHash": { "type": "string" }
        },
        "additionalProperties": false
      }
    },
    "evidence": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "path", "status", "contentHash"],
        "properties": {
          "id": { "type": "string" },
          "path": { "type": "string" },
          "status": {
            "enum": [
              "UNCHANGED",
              "CHANGED",
              "MISSING",
              "UNTRACKED",
              "OUTSIDE_PROJECT",
              "INACTIVE",
              "INVALID"
            ]
          },
          "contentHash": { "type": "string" }
        },
        "additionalProperties": false
      }
    },
    "implementations": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "path", "status", "contentHash"],
        "properties": {
          "id": { "type": "string" },
          "path": { "type": "string" },
          "status": {
            "enum": [
              "UNCHANGED",
              "CHANGED",
              "MISSING",
              "UNTRACKED",
              "OUTSIDE_PROJECT",
              "INACTIVE",
              "INVALID"
            ]
          },
          "contentHash": { "type": "string" }
        },
        "additionalProperties": false
      }
    },
    "validationCausality": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "status",
          "targetIds",
          "requiredInputIds",
          "missingInputIds",
          "staleInputIds"
        ],
        "properties": {
          "id": { "type": "string" },
          "status": {
            "enum": ["CURRENT", "INCOMPLETE", "STALE", "INVALID"]
          },
          "targetIds": {
            "type": "array",
            "items": { "type": "string" },
            "uniqueItems": true
          },
          "requiredInputIds": {
            "type": "array",
            "items": { "type": "string" },
            "uniqueItems": true
          },
          "missingInputIds": {
            "type": "array",
            "items": { "type": "string" },
            "uniqueItems": true
          },
          "staleInputIds": {
            "type": "array",
            "items": { "type": "string" },
            "uniqueItems": true
          }
        },
        "additionalProperties": false
      }
    },
    "invariants": {
      "type": "array",
      "items": {
        "$ref": "ontology-snapshot.schema.json#/$defs/invariantResult"
      }
    }
  },
  "additionalProperties": false
}
