{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aegis-gateway.dev/schemas/evidence-record.schema.json",
  "title": "Aegis Evidence Ledger Record",
  "description": "Hash-chained evidence record written to the Aegis audit ledger (OSFI E-23 Appendix 1 shape).",
  "type": "object",
  "required": ["seq", "prev_hash", "hash", "record_type"],
  "properties": {
    "seq": {
      "type": "integer",
      "minimum": 1,
      "description": "Monotonically-increasing sequence number (PRIMARY KEY)."
    },
    "prev_hash": {
      "type": "string",
      "description": "Hash of the previous record, or the literal string 'genesis' for the first record."
    },
    "hash": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$",
      "description": "sha256:<hex> of the canonical JSON of this record excluding the 'hash' field itself."
    },
    "record_type": {
      "type": "string",
      "enum": ["model_inventory", "run_evidence"]
    }
  },
  "oneOf": [
    {
      "title": "Model Inventory Record",
      "description": "Emitted once per registered route on server startup.",
      "properties": {
        "record_type": { "const": "model_inventory" },
        "model_id": { "type": "string" },
        "model_name": { "type": "string" },
        "model_description": { "type": ["string", "null"] },
        "model_risk_rating": { "type": ["string", "null"] },
        "model_owner": { "type": ["string", "null"] },
        "model_developer": { "type": "string" },
        "model_origin": { "type": "string" },
        "model_version": { "type": ["string", "null"] },
        "date_of_deployment": { "type": "string", "format": "date-time" },
        "model_dependencies": { "type": "array", "items": { "type": "string" } },
        "data_sources": { "type": "array", "items": { "type": "string" } },
        "approved_uses": { "type": "object" },
        "model_limitations": { "type": "array" },
        "monitoring_status": { "type": "string" },
        "date_of_most_recent_review": { "type": ["string", "null"] },
        "next_review_date": { "type": ["string", "null"] },
        "aegis_config_path": { "type": ["string", "null"] }
      },
      "required": ["record_type", "model_id", "model_developer", "date_of_deployment"]
    },
    {
      "title": "Run Evidence Record",
      "description": "Emitted once per completed, blocked, or denied pipeline run.",
      "properties": {
        "record_type": { "const": "run_evidence" },
        "run_id": { "type": "string", "format": "uuid" },
        "model_id": { "type": "string" },
        "model_version": { "type": ["string", "null"] },
        "principal_id": { "type": "string" },
        "created_at": { "type": "string" },
        "completed_at": { "type": "string", "format": "date-time" },
        "status": {
          "type": "string",
          "enum": ["completed", "blocked", "denied", "error", "running", "pending", "paused"]
        },
        "events": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "event_type": { "type": "string" },
              "stage": { "type": "string" },
              "node": { "type": "string" },
              "data": { "type": "object" }
            }
          }
        },
        "approver": {
          "type": ["object", "null"],
          "description": "Set when this record reflects a HITL /resume decision.",
          "properties": {
            "principal_id": { "type": "string" },
            "decision": { "type": "string" },
            "at": { "type": "string" }
          }
        }
      },
      "required": ["record_type", "run_id", "model_id", "principal_id", "completed_at", "status"]
    }
  ]
}
