{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://receiz.com/standards/receiz.document-verify.schema.v1.json",
  "title": "Receiz Document Verify Response v1",
  "description": "Canonical JSON response schema for POST /api/document-verify. This response contract includes success/failure and package flows; trusted single-artifact verification requires non-null bundle + anchor plus trusted-profile constraints on the embedded bundle.",
  "type": "object",
  "additionalProperties": false,
  "required": ["ok", "kind", "errors", "warnings", "bundle", "anchor", "package"],
  "$defs": {
    "hex64": {
      "type": "string",
      "pattern": "^[0-9a-fA-F]{64}$"
    },
    "anchorDataUrl": {
      "type": "string",
      "pattern": "^data:[^;]+;base64,[A-Za-z0-9+/=]+$"
    },
    "anchor": {
      "type": "object",
      "additionalProperties": false,
      "required": ["version", "parent", "anchorId", "anchoredAt"],
      "properties": {
        "version": {
          "const": 1
        },
        "parent": {
          "type": "object",
          "additionalProperties": false,
          "required": ["code", "pulse", "viewUrl"],
          "properties": {
            "code": {
              "type": "string"
            },
            "pulse": {
              "type": "string"
            },
            "viewUrl": {
              "type": "string"
            }
          }
        },
        "anchorId": {
          "type": "string",
          "pattern": "^[0-9a-f]{8}$"
        },
        "anchoredAt": {
          "type": "string"
        },
        "contextPreset": {
          "enum": ["Deposit", "Milestone", "Handoff", "Condition", "Agreement", "Delivery", "Custom"]
        },
        "claim": {
          "type": "object",
          "additionalProperties": false,
          "required": ["text", "sha256Hex"],
          "properties": {
            "text": {
              "type": "string"
            },
            "sha256Hex": {
              "$ref": "#/$defs/hex64"
            },
            "kind": {
              "type": "string"
            },
            "v": {
              "type": "integer"
            },
            "asset_type": {
              "enum": ["art", "diamond", "collectible", "luxury"]
            },
            "asset_id": {
              "type": "string"
            },
            "title": {
              "type": "string"
            },
            "creator_or_maker": {
              "type": "string"
            },
            "issuer_role": {
              "enum": ["collector", "gallery", "vault", "insurer", "appraiser"]
            },
            "custody_status": {
              "enum": ["minted", "in_custody", "transferred", "claimed"]
            },
            "custody_chain": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["at", "by", "role"],
                "properties": {
                  "at": {
                    "type": "string"
                  },
                  "by": {
                    "type": "string"
                  },
                  "role": {
                    "type": "string"
                  },
                  "note": {
                    "type": "string"
                  }
                }
              }
            },
            "attachments": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["name", "mime", "size", "dataUrl"],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "path": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "size": {
                    "type": "number"
                  },
                  "dataUrl": {
                    "$ref": "#/$defs/anchorDataUrl"
                  }
                }
              }
            }
          }
        },
        "file": {
          "type": "object",
          "additionalProperties": false,
          "required": ["name", "size", "mime", "sha256Hex"],
          "properties": {
            "name": {
              "type": "string"
            },
            "size": {
              "type": "number"
            },
            "mime": {
              "type": "string"
            },
            "sha256Hex": {
              "$ref": "#/$defs/hex64"
            },
            "dataUrl": {
              "$ref": "#/$defs/anchorDataUrl"
            },
            "url": {
              "type": "string"
            },
            "allowOriginalDownload": {
              "type": "boolean"
            },
            "allowDerivativeDownload": {
              "type": "boolean"
            },
            "allowMomentRecordDownload": {
              "type": "boolean"
            },
            "allowCopyDownload": {
              "type": "boolean",
              "deprecated": true
            },
            "gateAudioPlayback": {
              "type": "boolean"
            },
            "originalDownloadLimit": {
              "type": "number"
            },
            "derivativeDownloadLimit": {
              "type": "number"
            },
            "originalDownloadPriceCents": {
              "type": "number"
            },
            "derivativeDownloadPriceCents": {
              "type": "number"
            },
            "receizMs": {
              "type": "string"
            },
            "receizTzMinutesEast": {
              "type": "number"
            },
            "sealedName": {
              "type": "string"
            },
            "sealedSize": {
              "type": "number"
            },
            "sealedMime": {
              "type": "string"
            },
            "sealedSha256Hex": {
              "$ref": "#/$defs/hex64"
            },
            "sealedUrl": {
              "type": "string"
            },
            "sealedVerifyPath": {
              "type": "string"
            },
            "sealedCode": {
              "type": "string"
            },
            "sealedPulse": {
              "type": "string"
            },
            "sealedTs": {
              "type": "string"
            },
            "sealedKind": {
              "type": "string"
            },
            "audioCoverDataUrl": {
              "$ref": "#/$defs/anchorDataUrl"
            },
            "audioCoverUrl": {
              "type": "string"
            },
            "audioCoverName": {
              "type": "string"
            },
            "audioCoverMime": {
              "type": "string"
            },
            "audioCoverSize": {
              "type": "number"
            },
            "audioCoverSha256Hex": {
              "$ref": "#/$defs/hex64"
            },
            "audioReleaseTitle": {
              "type": "string"
            },
            "audioPrimaryArtist": {
              "type": "string"
            },
            "audioReleaseType": {
              "enum": ["single", "ep", "album", "mixtape", "live"]
            },
            "audioGenre": {
              "type": "string"
            },
            "audioSubgenre": {
              "type": "string"
            },
            "audioExplicit": {
              "type": "boolean"
            },
            "audioIsrc": {
              "type": "string"
            },
            "audioWriters": {
              "type": "string"
            },
            "audioProducer": {
              "type": "string"
            },
            "audioLabel": {
              "type": "string"
            },
            "audioReleaseDate": {
              "type": "string"
            },
            "audioTerritories": {
              "type": "string"
            }
          }
        }
      }
    },
    "packageItem": {
      "type": "object",
      "additionalProperties": false,
      "required": ["sourcePath", "sealedPath", "ok", "kind", "errors", "warnings", "code", "pulse", "ts"],
      "properties": {
        "sourcePath": {
          "type": "string"
        },
        "sealedPath": {
          "type": "string"
        },
        "ok": {
          "type": "boolean"
        },
        "kind": {
          "type": "string"
        },
        "errors": {
          "type": "array",
          "items": { "type": "string" }
        },
        "warnings": {
          "type": "array",
          "items": { "type": "string" }
        },
        "code": {
          "type": "string"
        },
        "pulse": {
          "type": "string"
        },
        "ts": {
          "type": "string"
        }
      }
    },
    "package": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "manifest",
        "manifestArtifactPath",
        "manifestArtifactVerified",
        "itemCount",
        "verifiedCount",
        "failedCount",
        "missingCount",
        "itemResults"
      ],
      "properties": {
        "manifest": {
          "type": "object"
        },
        "manifestArtifactPath": {
          "type": "string"
        },
        "manifestArtifactVerified": {
          "type": "boolean"
        },
        "itemCount": {
          "type": "number"
        },
        "verifiedCount": {
          "type": "number"
        },
        "failedCount": {
          "type": "number"
        },
        "missingCount": {
          "type": "number"
        },
        "itemResults": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/packageItem"
          }
        }
      }
    }
  },
  "properties": {
    "ok": {
      "type": "boolean"
    },
    "kind": {
      "enum": ["png", "pdf", "trailer", "bundle", "folder_package", "unknown"]
    },
    "errors": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "bundle": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "$ref": "https://receiz.com/standards/receiz.schema.v1.json"
        }
      ]
    },
    "anchor": {
      "description": "Null is allowed for package-level responses and failed verification outputs. Trusted single-artifact verdicts require an anchor object.",
      "oneOf": [
        {
          "type": "null"
        },
        {
          "$ref": "#/$defs/anchor"
        }
      ]
    },
    "package": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "$ref": "#/$defs/package"
        }
      ]
    }
  }
}
