{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mirmcsolutionweb.com/.well-known/mirmc-product-studio-lineage.schema.json",
  "title": "MIRMC Product Studio Governed Evidence Lineage Event",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "organization_id",
    "correlation_id",
    "sequence",
    "stage",
    "actor_kind",
    "payload",
    "previous_hash",
    "event_hash",
    "created_at"
  ],
  "properties": {
    "id": { "type": "string", "format": "uuid" },
    "organization_id": { "type": "string", "format": "uuid" },
    "correlation_id": { "type": "string", "format": "uuid" },
    "sequence": { "type": "integer", "minimum": 1, "maximum": 8 },
    "stage": {
      "type": "string",
      "enum": ["intent", "approval", "actor", "resource", "commit", "artifact", "runtime", "receipt"]
    },
    "actor_user_id": { "type": ["string", "null"], "format": "uuid" },
    "actor_kind": { "type": "string", "enum": ["human", "agent", "supervisor", "system"] },
    "actor_ref": { "type": ["string", "null"] },
    "resource_type": { "type": ["string", "null"] },
    "resource_ref": { "type": ["string", "null"] },
    "intent_ref": { "type": ["string", "null"] },
    "approval_ref": { "type": ["string", "null"] },
    "commit_sha": { "type": ["string", "null"], "pattern": "^[0-9a-fA-F]{40}$" },
    "artifact_ref": { "type": ["string", "null"] },
    "runtime_ref": { "type": ["string", "null"] },
    "receipt_ref": { "type": ["string", "null"] },
    "payload": { "type": "object" },
    "previous_hash": { "type": ["string", "null"], "pattern": "^[0-9a-f]{64}$" },
    "event_hash": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
    "created_at": { "type": "string", "format": "date-time" }
  },
  "allOf": [
    {
      "if": { "properties": { "stage": { "const": "intent" } }, "required": ["stage"] },
      "then": { "required": ["intent_ref"] }
    },
    {
      "if": { "properties": { "stage": { "const": "approval" } }, "required": ["stage"] },
      "then": { "required": ["approval_ref"] }
    },
    {
      "if": { "properties": { "stage": { "const": "resource" } }, "required": ["stage"] },
      "then": { "required": ["resource_type", "resource_ref"] }
    },
    {
      "if": { "properties": { "stage": { "const": "commit" } }, "required": ["stage"] },
      "then": { "required": ["commit_sha"] }
    },
    {
      "if": { "properties": { "stage": { "const": "artifact" } }, "required": ["stage"] },
      "then": { "required": ["artifact_ref"] }
    },
    {
      "if": { "properties": { "stage": { "const": "runtime" } }, "required": ["stage"] },
      "then": { "required": ["runtime_ref"] }
    },
    {
      "if": { "properties": { "stage": { "const": "receipt" } }, "required": ["stage"] },
      "then": { "required": ["receipt_ref"] }
    }
  ]
}
