{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/Eskasia/governseed/schemas/compile-receipt.schema.json",
  "title": "GovernSeed Policy Compile Receipt",
  "description": "A project-local receipt describing one deterministic policy compile transaction.",
  "type": "object",
  "required": [
    "schemaVersion",
    "compileId",
    "policyId",
    "inputHashes",
    "outputHashes",
    "target",
    "dryRun",
    "filesCreated",
    "filesUpdated",
    "filesUnchanged",
    "unsupportedControls",
    "warnings",
    "compiledAt",
    "ownership"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "compileId": {
      "$ref": "#/$defs/compileId"
    },
    "policyId": {
      "$ref": "#/$defs/policyId"
    },
    "inputHashes": {
      "$ref": "#/$defs/hashReferences"
    },
    "outputHashes": {
      "$ref": "#/$defs/hashReferences"
    },
    "target": {
      "enum": [
        "claude",
        "codex"
      ]
    },
    "dryRun": {
      "type": "boolean"
    },
    "filesCreated": {
      "$ref": "#/$defs/portablePaths"
    },
    "filesUpdated": {
      "$ref": "#/$defs/portablePaths"
    },
    "filesUnchanged": {
      "$ref": "#/$defs/portablePaths"
    },
    "unsupportedControls": {
      "$ref": "#/$defs/unsupportedControls"
    },
    "warnings": {
      "type": "array",
      "maxItems": 256,
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/reasonCode"
      }
    },
    "compiledAt": {
      "$ref": "#/$defs/timestamp"
    },
    "ownership": {
      "$ref": "#/$defs/ownership"
    }
  },
  "additionalProperties": false,
  "$defs": {
    "compileId": {
      "type": "string",
      "minLength": 9,
      "maxLength": 128,
      "pattern": "^COMPILE-[A-Z0-9](?:[A-Z0-9-]{0,118}[A-Z0-9])?$"
    },
    "policyId": {
      "type": "string",
      "minLength": 5,
      "maxLength": 128,
      "pattern": "^POL-[A-Z0-9](?:[A-Z0-9-]{0,122}[A-Z0-9])?$"
    },
    "controlId": {
      "type": "string",
      "minLength": 5,
      "maxLength": 128,
      "pattern": "^POL-[A-Z0-9](?:[A-Z0-9-]{0,122}[A-Z0-9])?$"
    },
    "reasonCode": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "pattern": "^[A-Z][A-Z0-9_]*$"
    },
    "sha256": {
      "type": "string",
      "minLength": 64,
      "maxLength": 64,
      "pattern": "^[0-9a-f]{64}$"
    },
    "portablePath": {
      "type": "string",
      "minLength": 1,
      "maxLength": 512,
      "pattern": "^(?!.*(?:^|/)\\.{1,2}(?:/|$))[A-Za-z0-9._@+-]+(?:/[A-Za-z0-9._@+-]+)*$"
    },
    "timestamp": {
      "type": "string",
      "minLength": 20,
      "maxLength": 64,
      "format": "date-time"
    },
    "hashReference": {
      "type": "object",
      "required": [
        "path",
        "sha256"
      ],
      "properties": {
        "path": {
          "$ref": "#/$defs/portablePath"
        },
        "sha256": {
          "$ref": "#/$defs/sha256"
        }
      },
      "additionalProperties": false
    },
    "hashReferences": {
      "type": "array",
      "minItems": 1,
      "maxItems": 512,
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/hashReference"
      }
    },
    "portablePaths": {
      "type": "array",
      "maxItems": 256,
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/portablePath"
      }
    },
    "unsupportedControl": {
      "type": "object",
      "required": [
        "controlId",
        "capability",
        "target",
        "support",
        "reasonCode"
      ],
      "properties": {
        "controlId": {
          "$ref": "#/$defs/controlId"
        },
        "capability": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256,
          "pattern": "^[a-z][a-z0-9.-]*$"
        },
        "target": {
          "enum": [
            "claude",
            "codex"
          ]
        },
        "support": {
          "const": "unsupported"
        },
        "reasonCode": {
          "$ref": "#/$defs/reasonCode"
        }
      },
      "additionalProperties": false
    },
    "unsupportedControls": {
      "type": "array",
      "maxItems": 256,
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/unsupportedControl"
      }
    },
    "ownership": {
      "type": "object",
      "required": [
        "generator",
        "artifactType"
      ],
      "properties": {
        "generator": {
          "const": "GovernSeed"
        },
        "artifactType": {
          "const": "compile-receipt"
        }
      },
      "additionalProperties": false
    }
  }
}
