{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://kaldenframelabs.com/schemas/artifact-admission-decision-v1.schema.json",
  "title": "Artifact Admission Decision v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "decision", "policy", "subject", "receipt", "checked_at", "summary", "checks", "boundary"],
  "properties": {
    "schema": { "const": "kaldenframe.artifact-admission.decision.v1" },
    "decision": { "enum": ["ADMIT", "DENY"] },
    "policy": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "version", "stage"],
      "properties": {
        "id": { "$ref": "#/$defs/nullableId" },
        "version": { "$ref": "#/$defs/nullableId" },
        "stage": { "$ref": "#/$defs/nullableId" }
      }
    },
    "subject": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "sha256"],
      "properties": {
        "path": { "type": ["string", "null"] },
        "sha256": { "anyOf": [{ "$ref": "#/$defs/sha256" }, { "type": "null" }] }
      }
    },
    "receipt": {
      "anyOf": [
        { "type": "null" },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["file", "sha256", "id", "state", "verified_at", "verifier"],
          "properties": {
            "file": { "type": "string", "minLength": 1 },
            "sha256": { "$ref": "#/$defs/sha256" },
            "id": { "$ref": "#/$defs/id" },
            "state": { "$ref": "#/$defs/id" },
            "verified_at": { "type": "string", "format": "date-time" },
            "verifier": {
              "type": "object",
              "additionalProperties": false,
              "required": ["name", "version", "source_sha256"],
              "properties": {
                "name": { "$ref": "#/$defs/id" },
                "version": { "$ref": "#/$defs/id" },
                "source_sha256": { "anyOf": [{ "$ref": "#/$defs/sha256" }, { "type": "null" }] }
              }
            }
          }
        }
      ]
    },
    "checked_at": { "type": "string", "format": "date-time" },
    "summary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["passed", "denied"],
      "properties": {
        "passed": { "type": "integer", "minimum": 0 },
        "denied": { "type": "integer", "minimum": 0 }
      }
    },
    "checks": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "status", "message"],
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "status": { "enum": ["PASS", "DENY"] },
          "message": { "type": "string", "minLength": 1 },
          "details": true
        }
      }
    },
    "boundary": {
      "const": "Local consistency and policy admission only; not a signature, provenance attestation, security audit, or guarantee that an artifact is safe or fit for use."
    }
  },
  "$defs": {
    "id": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$" },
    "nullableId": { "anyOf": [{ "$ref": "#/$defs/id" }, { "type": "null" }] },
    "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
  }
}
