{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://kinra.ai/docs/truth-machine/schemas/publication.schema.json",
  "title": "Truth Machine reference publication packet",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "id", "title", "status", "created_on", "source_revision", "specification_version", "artifact_manifest_sha256", "generated_manifest_sha256", "document", "change", "evidence"],
  "properties": {
    "schema_version": {"const": 1},
    "id": {"type": "string", "pattern": "^TMP-[0-9]{4}$"},
    "title": {"type": "string", "minLength": 1},
    "status": {"enum": ["built", "approved", "deployed", "verified", "superseded", "withdrawn"]},
    "created_on": {"type": "string", "format": "date"},
    "source_revision": {"type": "string", "pattern": "^[a-f0-9]{40}$"},
    "specification_version": {"type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"},
    "artifact_manifest_sha256": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
    "generated_manifest_sha256": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
    "artifact_sha256": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
    "artifact_file_count": {"type": "integer", "minimum": 1},
    "artifact_bytes": {"type": "integer", "minimum": 1},
    "document": {"const": "README.md"},
    "change": {"type": "string", "pattern": "^TMC-[0-9]{4}$"},
    "evidence": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {"type": "string", "pattern": "^TME-[0-9]{8}-[0-9]{4}$"}
    },
    "approved_by": {"type": "string", "minLength": 1},
    "approved_on": {"type": "string", "format": "date"},
    "deployment_revision": {"type": "string", "pattern": "^[a-f0-9]{40}$"},
    "deployed_release": {"type": "string", "minLength": 1},
    "edge_revision": {"type": "string", "pattern": "^[a-f0-9]{40}$"},
    "public_url": {"type": "string", "format": "uri", "pattern": "^https://"},
    "verified_at": {"type": "string", "format": "date-time"},
    "rollback": {"type": "string", "minLength": 1},
    "supersedes": {"type": "string", "pattern": "^TMP-[0-9]{4}$"}
  },
  "allOf": [
    {
      "if": {"properties": {"status": {"const": "verified"}}},
      "then": {
        "required": ["artifact_sha256", "artifact_file_count", "artifact_bytes", "approved_by", "approved_on", "deployment_revision", "deployed_release", "edge_revision", "public_url", "verified_at", "rollback"]
      }
    }
  ]
}
