{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://vizai.io/schema/publication-receipt/v1.0",
  "title": "VizAI Public-Safe Publication Receipt",
  "description": "Companion provenance for one public registry profile. It contains hashes and non-sensitive lineage references, never raw evidence, personal approver identity, private notes, or consent records.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "receiptId",
    "entitySlug",
    "profileVersion",
    "artifact",
    "source",
    "publication",
    "approval"
  ],
  "properties": {
    "schemaVersion": {
      "const": "1.0"
    },
    "receiptId": {
      "type": "string",
      "pattern": "^publication:[a-z0-9]+(?:-[a-z0-9]+)*:[1-9][0-9]*$"
    },
    "entitySlug": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "profileVersion": {
      "type": "integer",
      "minimum": 1
    },
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "path",
        "mediaType",
        "bytes",
        "sha256",
        "canonicalJsonSha256"
      ],
      "properties": {
        "path": {
          "type": "string",
          "pattern": "^registry/[a-z0-9]+(?:-[a-z0-9]+)*/profile\\.json$"
        },
        "mediaType": {
          "const": "application/json"
        },
        "bytes": {
          "type": "integer",
          "minimum": 1
        },
        "sha256": {
          "$ref": "#/definitions/sha256"
        },
        "canonicalJsonSha256": {
          "$ref": "#/definitions/sha256"
        }
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "system",
        "repository",
        "commitSha",
        "lineage"
      ],
      "properties": {
        "type": {
          "enum": [
            "vizai-discovery-canon",
            "public-source-review",
            "historical-registry-migration"
          ]
        },
        "system": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "repository": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$"
        },
        "commitSha": {
          "type": "string",
          "pattern": "^[0-9a-f]{40}$"
        },
        "canonVersion": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        },
        "lineage": {
          "type": "array",
          "minItems": 1,
          "maxItems": 100,
          "uniqueItems": true,
          "items": {
            "$ref": "#/definitions/lineageInput"
          }
        }
      }
    },
    "publication": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "policyVersion",
        "consentReceipt"
      ],
      "properties": {
        "policyVersion": {
          "const": "1.0"
        },
        "consentReceipt": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "status",
            "reference"
          ],
          "properties": {
            "status": {
              "enum": [
                "recorded",
                "not-required-public-observation"
              ]
            },
            "reference": {
              "type": "string",
              "pattern": "^[A-Za-z][A-Za-z0-9._:-]{2,127}$"
            }
          }
        }
      }
    },
    "approval": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "preparedAt",
        "approvedAt",
        "workflow"
      ],
      "properties": {
        "status": {
          "enum": [
            "approved",
            "historical-migration"
          ]
        },
        "preparedAt": {
          "type": "string",
          "format": "date-time"
        },
        "approvedAt": {
          "type": "string",
          "format": "date-time"
        },
        "workflow": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        }
      }
    }
  },
  "definitions": {
    "sha256": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "lineageInput": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "sourceClass",
        "reference",
        "observedAt",
        "contentDigest"
      ],
      "properties": {
        "kind": {
          "enum": [
            "canon",
            "crawl-snapshot",
            "public-document",
            "manual-review",
            "registry-history"
          ]
        },
        "sourceClass": {
          "enum": [
            "first-party",
            "business-supplied",
            "official-registry",
            "third-party",
            "approved-publication"
          ]
        },
        "reference": {
          "type": "string",
          "pattern": "^[A-Za-z][A-Za-z0-9._:-]{2,191}$"
        },
        "observedAt": {
          "type": "string",
          "format": "date-time"
        },
        "contentDigest": {
          "$ref": "#/definitions/sha256"
        },
        "publicUrl": {
          "type": "string",
          "format": "uri",
          "maxLength": 2048
        }
      }
    }
  }
}
