{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://wdy.org/certified/rules/wdy-manifest-v0.1.schema.json",
  "title": "WDY Provenance Manifest v0.1",
  "type": "object",
  "required": [
    "manifest_version", "record_id", "title", "content_type",
    "file", "provenance", "ai_disclosure", "signer", "created_at", "signature"
  ],
  "properties": {
    "manifest_version": { "const": "0.1" },
    "record_id": { "type": "string", "pattern": "^WDY-\\d{4}-\\d{3,}(-DEMO)?(-[0-9A-Z]{6})?$" },
    "title": { "type": "string", "minLength": 1 },
    "content_type": { "enum": ["video", "script", "storyboard", "poster", "report", "document", "dataset", "webpage"] },
    "file": {
      "type": "object",
      "required": ["filename", "size_bytes", "sha256"],
      "properties": {
        "filename": { "type": "string" },
        "size_bytes": { "type": "integer", "minimum": 1 },
        "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
      }
    },
    "provenance": {
      "type": "object",
      "required": ["production_mode", "ai_generated_ratio", "live_action_ratio"],
      "properties": {
        "production_mode": { "enum": ["ai", "live", "hybrid", "authored"] },
        "ai_tools": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["name"],
            "properties": {
              "name": { "type": "string" },
              "role": { "type": "string" }
            }
          }
        },
        "ai_generated_ratio": { "type": "number", "minimum": 0, "maximum": 1 },
        "live_action_ratio": { "type": "number", "minimum": 0, "maximum": 1 }
      }
    },
    "ai_disclosure": {
      "type": "object",
      "required": ["visible_label", "metadata_marking"],
      "properties": {
        "visible_label": { "type": "boolean" },
        "metadata_marking": { "type": "boolean" },
        "basis": { "type": "string" },
        "eu_ai_act_article_50": {
          "type": "object",
          "required": ["applicable"],
          "properties": {
            "applicable": { "type": "boolean" },
            "machine_readable_marking": {
              "type": "object",
              "properties": {
                "metadata": { "type": "boolean" },
                "pixel_watermark": { "type": ["boolean", "null"] }
              }
            },
            "disclosure_log_url": { "type": ["string", "null"] }
          }
        }
      }
    },
    "rights_claims": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["role", "party"],
        "properties": {
          "role": { "type": "string" },
          "party": { "type": "string" },
          "basis": { "type": "string" },
          "scope": { "type": "string" }
        }
      }
    },
    "rights_evidence": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["filename", "sha256"],
        "properties": {
          "filename": { "type": "string" },
          "size_bytes": { "type": "integer", "minimum": 1 },
          "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
        }
      }
    },
    "contact": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "email": { "type": "string" },
        "org": { "type": "string" }
      }
    },
    "anchors": {
      "type": "object",
      "properties": {
        "tsa": {
          "type": ["object", "null"],
          "properties": {
            "provider": { "type": "string" },
            "serial": { "type": "string" },
            "timestamp": { "type": "string" },
            "gen_time": { "type": "string" },
            "policy": { "type": "string" },
            "digest_algorithm": { "type": "string" },
            "message_imprint": { "type": "string" },
            "tsr_file": { "type": "string" },
            "tsr_sha256": { "type": "string" },
            "endpoint": { "type": "string" },
            "ca_hint": { "type": "string" },
            "stamped_at": { "type": "string" }
          }
        },
        "opentimestamps": {
          "type": ["object", "null"],
          "properties": {
            "type": { "type": "string" },
            "protocol": { "type": "string" },
            "chain": { "type": "string" },
            "digest_algorithm": { "type": "string" },
            "message_digest": { "type": "string" },
            "calendars": { "type": "array", "items": { "type": "string" } },
            "proof_file": { "type": "string" },
            "proof_sha256": { "type": "string" },
            "status": { "enum": ["pending", "confirmed"] },
            "block_height": { "type": ["integer", "null"] },
            "submitted_at": { "type": "string" },
            "confirmed_at": { "type": ["string", "null"] }
          }
        },
        "zhixin": {
          "type": ["object", "null"],
          "properties": {
            "type": { "type": "string" },
            "chain": { "type": "string" },
            "api_endpoint": { "type": "string" },
            "anchor_target": { "type": "string" },
            "hash_sm3": { "type": "string" },
            "ev_id": { "type": "string" },
            "tx_id": { "type": "string" },
            "block_height": { "type": "integer" },
            "tx_time": { "type": "string" },
            "extend_info": { "type": "string" },
            "cert_url": { "type": "string" },
            "anchored_at": { "type": "string" }
          }
        },
        "storage": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["type", "ref"],
            "properties": {
              "type": { "enum": ["arweave", "s3", "ipfs"] },
              "ref": { "type": "string" }
            }
          }
        }
      }
    },
    "c2pa_mapping": { "type": "object" },
    "request": {
      "type": "object",
      "properties": {
        "evidence_tier": { "enum": ["standard", "tsa", "judicial"] },
        "referral": { "type": "string", "pattern": "^[A-Z0-9][A-Z0-9-]{1,15}$" }
      }
    },
    "signer": {
      "type": "object",
      "required": ["name", "key_id"],
      "properties": {
        "name": { "type": "string" },
        "key_id": { "type": "string", "pattern": "^\\d{4}-rot\\d+(-[a-z]+)?$" }
      }
    },
    "created_at": { "type": "string", "format": "date-time" },
    "signature": {
      "type": "object",
      "required": ["alg", "key_id", "created_at", "value"],
      "properties": {
        "alg": { "const": "Ed25519" },
        "key_id": { "type": "string" },
        "created_at": { "type": "string" },
        "value": { "type": "string", "pattern": "^[A-Za-z0-9+/=]+$" }
      }
    }
  }
}
