{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.nothinghuman.org/data/attestation/v1/schema.json",
  "title": "Archive Attestation Protocol claim",
  "type": "object",
  "required": [
    "schema_version", "claim_id", "route", "text", "source_register",
    "epistemic_status", "review_status", "evidence", "review", "rights",
    "provenance"
  ],
  "properties": {
    "schema_version": {"const": "1.0.0"},
    "claim_id": {"type": "string", "pattern": "^AAP-[A-Z0-9]+-[0-9]{4}$"},
    "route": {"type": "string", "pattern": "^/"},
    "text": {"type": "string", "minLength": 1},
    "source_register": {
      "enum": ["documentary", "interpretive", "exhibit-fiction", "machine-observation"]
    },
    "epistemic_status": {
      "enum": ["primary-local", "primary-external", "derived", "interpretive", "unverified", "contested", "refuted", "exhibit-fiction"]
    },
    "review_status": {"enum": ["draft", "reviewed", "superseded", "withdrawn"]},
    "evidence": {"type": "array", "items": {"$ref": "#/$defs/evidence"}},
    "derivation": {"$ref": "#/$defs/derivation"},
    "interpretation": {"$ref": "#/$defs/interpretation"},
    "verification": {"$ref": "#/$defs/verification"},
    "review": {"$ref": "#/$defs/review"},
    "rights": {"$ref": "#/$defs/rights"},
    "provenance": {"$ref": "#/$defs/provenance"}
  },
  "additionalProperties": false,
  "$defs": {
    "evidence": {
      "type": "object",
      "required": ["evidence_id", "kind", "source_ref", "source_label", "locator", "quote", "checksum", "rights_state", "display_policy"],
      "properties": {
        "evidence_id": {"type": "string", "minLength": 1},
        "kind": {"enum": ["local-file", "external-url", "corpus-passage", "model-output", "derivation-rule", "correction-record"]},
        "source_ref": {"type": "string", "minLength": 1},
        "source_label": {"type": "string", "minLength": 1},
        "locator": {"type": "string", "minLength": 1},
        "quote": {"type": "string", "minLength": 1},
        "checksum": {"type": "string", "pattern": "^sha256:[a-f0-9]{64}$"},
        "url": {"type": "string", "format": "uri"},
        "accessed_at": {"type": "string", "format": "date"},
        "rights_state": {"type": "string", "minLength": 1},
        "display_policy": {"enum": ["metadata-only", "short-quote", "full-quote", "private"]}
      },
      "additionalProperties": false
    },
    "derivation": {
      "type": "object",
      "required": ["method", "input_claim_ids", "rule_source", "rule_quote", "implementation", "version"],
      "properties": {
        "method": {"type": "string", "minLength": 1},
        "input_claim_ids": {"type": "array", "minItems": 1, "items": {"type": "string", "pattern": "^AAP-"}},
        "rule_source": {"type": "string", "minLength": 1},
        "rule_quote": {"type": "string", "minLength": 1},
        "implementation": {"type": "string", "minLength": 1},
        "version": {"type": "string", "minLength": 1}
      },
      "additionalProperties": false
    },
    "interpretation": {
      "type": "object",
      "required": ["editor", "supporting_claim_ids"],
      "properties": {
        "editor": {"type": "string", "minLength": 1},
        "supporting_claim_ids": {"type": "array", "minItems": 1, "items": {"type": "string", "pattern": "^AAP-"}}
      },
      "additionalProperties": false
    },
    "verification": {
      "type": "object",
      "required": ["scope", "method", "searched_at", "positive_contrary_evidence"],
      "properties": {
        "scope": {"type": "string", "minLength": 1},
        "method": {"type": "string", "minLength": 1},
        "searched_at": {"type": "string", "format": "date"},
        "positive_contrary_evidence": {"type": "boolean"}
      },
      "additionalProperties": false
    },
    "review": {
      "type": "object",
      "required": ["reviewer", "reviewed_at", "note"],
      "properties": {
        "reviewer": {"type": "string", "minLength": 1},
        "reviewed_at": {"type": "string", "format": "date"},
        "note": {"type": "string", "minLength": 1}
      },
      "additionalProperties": false
    },
    "rights": {
      "type": "object",
      "required": ["public_display", "quote_word_cap", "nosnippet"],
      "properties": {
        "public_display": {"enum": ["metadata-only", "short-quote", "full-quote", "private"]},
        "quote_word_cap": {"type": "integer", "minimum": 0, "maximum": 200},
        "nosnippet": {"type": "boolean"}
      },
      "additionalProperties": false
    },
    "provenance": {
      "type": "object",
      "required": ["created_at", "updated_at", "source_commit"],
      "properties": {
        "created_at": {"type": "string", "format": "date"},
        "updated_at": {"type": "string", "format": "date"},
        "source_commit": {"type": "string", "minLength": 7},
        "session_ref": {"type": "string"}
      },
      "additionalProperties": false
    }
  }
}
