{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://dicworkflowkit.local/schemas/ontology-action.schema.json",
  "title": "DIC Ontology Action",
  "description": "Auditable request to change ontology or repository state.",
  "type": "object",
  "required": [
    "schema",
    "id",
    "type",
    "actor",
    "status",
    "targets",
    "preconditions",
    "postconditions",
    "evidence"
  ],
  "properties": {
    "schema": { "const": "dic.ontology-action.v1" },
    "id": {
      "type": "string",
      "pattern": "^act-[a-zA-Z0-9._:-]+$"
    },
    "type": {
      "enum": [
        "IntakeDesignSource",
        "ConfirmObligation",
        "ObserveImplementation",
        "OpenGap",
        "ProposeRepair",
        "ApproveRepair",
        "ApplyRepair",
        "RunValidation",
        "AttachEvidence",
        "CloseGap",
        "MarkBlocked",
        "SupersedeSource",
        "RegisterCandidate",
        "RecordGateRun",
        "AssertClaim",
        "ChallengeClaim",
        "RecordCounterexample",
        "RecordDecision",
        "RecordWaiver",
        "RegisterPolicy"
      ]
    },
    "actor": { "type": "string", "minLength": 1 },
    "expectedSnapshotRevision": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$",
      "description": "Optional optimistic-concurrency precondition for authored actions."
    },
    "status": {
      "enum": [
        "proposed",
        "approved",
        "in_progress",
        "completed",
        "rejected",
        "blocked",
        "rolled_back"
      ]
    },
    "targets": {
      "type": "array",
      "items": { "type": "string" },
      "minItems": 1,
      "uniqueItems": true
    },
    "parameters": {
      "type": "object",
      "properties": {
        "ontologyPatch": {
          "$ref": "ontology-patch.schema.json"
        }
      },
      "additionalProperties": true
    },
    "preconditions": {
      "type": "array",
      "items": { "$ref": "#/$defs/condition" }
    },
    "postconditions": {
      "type": "array",
      "items": { "$ref": "#/$defs/condition" }
    },
    "allowedPaths": {
      "type": "array",
      "items": { "type": "string" },
      "uniqueItems": true
    },
    "evidence": {
      "type": "array",
      "items": { "type": "string" },
      "uniqueItems": true
    },
    "rollback": {
      "type": ["string", "null"]
    }
  },
  "$defs": {
    "condition": {
      "type": "object",
      "required": ["description", "status"],
      "properties": {
        "description": { "type": "string", "minLength": 1 },
        "status": { "enum": ["PENDING", "PASS", "FAIL"] },
        "evidence": {
          "type": "array",
          "items": { "type": "string" }
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
