{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://attestome.example/schemas/research-artifact-receipt.schema.json",
  "title": "Attestome Research Artifact Receipt",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "kind",
    "version",
    "mode",
    "scope",
    "createdAt",
    "artifact",
    "file",
    "redaction",
    "claims",
    "note",
    "receiptDigest"
  ],
  "properties": {
    "kind": { "const": "attestome.research-artifact-receipt" },
    "version": { "const": "1.0" },
    "mode": { "enum": ["local", "sample"] },
    "scope": { "enum": ["file-backed", "metadata-only"] },
    "createdAt": { "type": "string", "format": "date-time" },
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "projectTitle",
        "artifactType",
        "studyStage",
        "protocolVersion",
        "researchId",
        "contributor",
        "collectedAt",
        "tags"
      ],
      "properties": {
        "projectTitle": { "type": "string", "minLength": 1, "maxLength": 160 },
        "artifactType": { "type": "string", "minLength": 1, "maxLength": 100 },
        "studyStage": { "type": "string", "minLength": 1, "maxLength": 100 },
        "protocolVersion": { "type": "string", "minLength": 1, "maxLength": 80 },
        "researchId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80,
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:/-]*$"
        },
        "contributor": { "type": "string", "minLength": 1, "maxLength": 120 },
        "collectedAt": { "type": "string", "format": "date-time" },
        "tags": {
          "type": "array",
          "maxItems": 8,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1, "maxLength": 32 }
        }
      }
    },
    "file": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["name", "sizeBytes", "mimeType", "lastModified", "digest"],
          "properties": {
            "name": { "type": "string", "minLength": 1, "maxLength": 255 },
            "sizeBytes": { "type": "integer", "minimum": 0, "maximum": 26214400 },
            "mimeType": { "type": "string", "minLength": 1, "maxLength": 160 },
            "lastModified": {
              "oneOf": [
                { "type": "string", "format": "date-time" },
                { "type": "null" }
              ]
            },
            "digest": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" }
          }
        },
        { "type": "null" }
      ]
    },
    "redaction": {
      "type": "object",
      "additionalProperties": false,
      "required": ["confirmed", "basis", "note"],
      "properties": {
        "confirmed": { "const": true },
        "basis": { "const": "self-attested" },
        "note": { "type": "string", "minLength": 1 }
      }
    },
    "claims": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "contentStored",
        "uploaded",
        "identityVerified",
        "authorshipVerified",
        "provenanceVerified"
      ],
      "properties": {
        "contentStored": { "const": false },
        "uploaded": { "const": false },
        "identityVerified": { "const": false },
        "authorshipVerified": { "const": false },
        "provenanceVerified": { "const": false }
      }
    },
    "note": { "type": "string", "minLength": 1 },
    "receiptDigest": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" }
  },
  "allOf": [
    {
      "if": { "properties": { "scope": { "const": "file-backed" } } },
      "then": { "properties": { "file": { "type": "object" } } }
    },
    {
      "if": { "properties": { "scope": { "const": "metadata-only" } } },
      "then": { "properties": { "file": { "const": null } } }
    }
  ]
}
