{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://kinra.ai/docs/truth-machine/schemas/change.schema.json",
  "title": "Truth Machine reference change packet",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "id", "slug", "title", "status", "created_on", "expected_revision", "document", "actor", "evidence", "transitions"],
  "properties": {
    "schema_version": {"const": 1},
    "id": {"type": "string", "pattern": "^TMC-[0-9]{4}$"},
    "slug": {"type": "string", "pattern": "^[a-z][a-z0-9-]*$"},
    "title": {"type": "string", "minLength": 1},
    "status": {"enum": ["proposed", "accepted", "stale", "rejected"]},
    "created_on": {"type": "string", "format": "date"},
    "accepted_on": {"type": "string", "format": "date"},
    "expected_revision": {"type": "string", "pattern": "^[a-f0-9]{40}$"},
    "resulting_revision": {"type": "string", "pattern": "^[a-f0-9]{40}$"},
    "document": {"const": "README.md"},
    "actor": {"type": "string", "minLength": 1},
    "reviewed_by": {"type": "string", "minLength": 1},
    "acceptance_evidence": {"type": "string", "pattern": "^TME-[0-9]{8}-[0-9]{4}$"},
    "proposal_sha256": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
    "evidence": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {"type": "string", "pattern": "^TME-[0-9]{8}-[0-9]{4}$"}
    },
    "publications": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {"type": "string", "pattern": "^TMP-[0-9]{4}$"}
    },
    "transitions": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["domain", "after"],
        "properties": {
          "domain": {"type": "string", "pattern": "^[a-z][a-z0-9-]*$"},
          "before": {"type": "string", "pattern": "^TMR-[0-9]{4}$"},
          "after": {"type": "string", "pattern": "^TMR-[0-9]{4}$"}
        }
      }
    }
  },
  "allOf": [
    {
      "if": {"properties": {"status": {"const": "accepted"}}},
      "then": {"required": ["accepted_on", "reviewed_by", "acceptance_evidence", "proposal_sha256"]}
    }
  ]
}
