{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://bpa.local/schemas/asset-record/v1alpha1",
  "title": "BPA Asset Record v1alpha1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "apiVersion",
    "kind",
    "assetId",
    "digest",
    "size",
    "mediaType",
    "storageRef",
    "classification",
    "sourceIds",
    "createdAt",
    "retention"
  ],
  "properties": {
    "apiVersion": { "const": "bpa.asset/v1alpha1" },
    "kind": { "const": "AssetRecord" },
    "assetId": { "$ref": "#/$defs/id" },
    "digest": { "$ref": "#/$defs/digest" },
    "size": {
      "type": "integer",
      "minimum": 1,
      "maximum": 26214400
    },
    "mediaType": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "pattern": "^[A-Za-z0-9!#$&^_.+-]+/[A-Za-z0-9!#$&^_.+-]+$"
    },
    "storageRef": {
      "type": "string",
      "minLength": 83,
      "maxLength": 83,
      "pattern": "^asset-store:sha256:[a-f0-9]{64}$"
    },
    "classification": {
      "enum": ["public", "internal", "confidential", "restricted"]
    },
    "sourceIds": {
      "type": "array",
      "minItems": 1,
      "maxItems": 100,
      "uniqueItems": true,
      "items": { "$ref": "#/$defs/id" }
    },
    "derivedFromAssetIds": {
      "type": "array",
      "minItems": 1,
      "maxItems": 100,
      "uniqueItems": true,
      "items": { "$ref": "#/$defs/id" }
    },
    "createdAt": { "$ref": "#/$defs/timestamp" },
    "retention": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["policy", "retainUntil"],
          "properties": {
            "policy": { "enum": ["restricted_24h", "public_30d"] },
            "retainUntil": { "$ref": "#/$defs/timestamp" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["policy"],
          "properties": {
            "policy": { "enum": ["reference_pack", "manual"] }
          }
        }
      ]
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
    },
    "digest": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" },
    "timestamp": { "type": "string", "format": "date-time" }
  }
}
