{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artiore.com/schemas/evidence-ledger-v1.json",
  "title": "ARTIore evidence exchange v1.1",
  "description": "Version 1.1. One evidence record, a list of evidence records, one correction request, a list of correction requests, or an exchange file with schema_version 1.1. This supersedes the QA proposal exchange.schema.json, which pinned schema_version 1.0 and only required a claim id, statement, status, an untyped sources array, and a free-text publication_status, plus a correction id, claim id, reason, and free-text status. Those ideas are kept: a versioned exchange object, additionalProperties false, at most 2000 records, and the ART-EVD / ART-COR id patterns. Version 1.0 is rejected because it did not enforce the rest. Normative checks live in src/lib/evidence/validate.ts and scripts/validate-evidence.py. A date-time must be a real RFC 3339 instant with a timezone. A URL must be http or https, with no userinfo and no javascript:, data:, vbscript:, file:, or blob: scheme. Sources are objects, not bare strings. PUBLISHED and APPROVED evidence requires human_approval. ACCEPTED and PUBLISHED corrections require publication_authorization, plus the original wording, the proposed wording, and a list of links. Those fields are not proof that a person approved anything. CORRECTED evidence requires revision history that keeps the previous wording. DISPUTED evidence requires conflicting evidence. VERIFIED evidence requires a method, a time, and at least one source. A contradiction flag is a review note, not a record that can be imported as a verdict.",
  "oneOf": [
    { "$ref": "#/$defs/record" },
    { "$ref": "#/$defs/recordList" },
    { "$ref": "#/$defs/correction" },
    { "$ref": "#/$defs/correctionList" },
    { "$ref": "#/$defs/exchange" }
  ],
  "$defs": {
    "safeUrl": {
      "type": "string",
      "format": "uri",
      "pattern": "^https?://",
      "description": "Absolute http or https URL. Validators also reject userinfo and unsafe schemes such as javascript:."
    },
    "dateTime": {
      "type": "string",
      "format": "date-time",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]+)?(Z|[+-][0-9]{2}:[0-9]{2})$",
      "description": "Validators also reject impossible calendar dates."
    },
    "recordList": {
      "type": "array",
      "minItems": 1,
      "maxItems": 2000,
      "items": { "$ref": "#/$defs/record" }
    },
    "approval": {
      "type": "object",
      "additionalProperties": false,
      "required": ["approver", "approved_at", "action"],
      "properties": {
        "approver": { "type": "string", "minLength": 1 },
        "approved_at": { "$ref": "#/$defs/dateTime" },
        "action": { "type": "string", "minLength": 1 }
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": ["url", "source_type", "accessed_at"],
      "properties": {
        "url": { "$ref": "#/$defs/safeUrl" },
        "source_type": { "enum": ["PRIMARY", "SECONDARY", "USER_REPORT", "OTHER"] },
        "accessed_at": { "$ref": "#/$defs/dateTime" },
        "archived_url": { "type": ["string", "null"], "format": "uri" },
        "note": { "type": "string" }
      }
    },
    "conflict": {
      "type": "object",
      "additionalProperties": false,
      "required": ["statement"],
      "properties": {
        "statement": { "type": "string", "minLength": 1 },
        "source_url": { "type": ["string", "null"] }
      }
    },
    "revision": {
      "type": "object",
      "additionalProperties": false,
      "required": ["timestamp", "summary", "previous_statement"],
      "properties": {
        "timestamp": { "$ref": "#/$defs/dateTime" },
        "summary": { "type": "string", "minLength": 1 },
        "previous_statement": {
          "type": "string",
          "minLength": 1,
          "description": "The wording this revision replaced. Do not drop it."
        },
        "previous_claim_id": { "type": "string", "pattern": "^ART-EVD-[0-9]{4,}$" }
      }
    },
    "record": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "claim_id",
        "statement",
        "status",
        "sources",
        "scope",
        "limitations",
        "publication_status",
        "revision_history"
      ],
      "properties": {
        "claim_id": { "type": "string", "pattern": "^ART-EVD-[0-9]{4,}$" },
        "statement": { "type": "string", "minLength": 1 },
        "status": {
          "enum": [
            "VERIFIED",
            "SUPPORTED_INFERENCE",
            "DISPUTED",
            "UNVERIFIED",
            "BELIEF_INTERPRETATION",
            "CORRECTED"
          ]
        },
        "sources": { "type": "array", "items": { "$ref": "#/$defs/source" } },
        "scope": { "type": "string", "minLength": 1 },
        "limitations": { "type": "array", "items": { "type": "string", "minLength": 1 } },
        "verification_method": { "type": ["string", "null"] },
        "verified_at": { "type": ["string", "null"], "format": "date-time" },
        "conflicting_evidence": { "type": "array", "items": { "$ref": "#/$defs/conflict" } },
        "publication_status": { "enum": ["DRAFT", "REVIEW", "APPROVED", "PUBLISHED", "RETRACTED"] },
        "human_approval": { "type": ["object", "null"] },
        "revision_history": { "type": "array", "items": { "$ref": "#/$defs/revision" } }
      },
      "allOf": [
        {
          "if": {
            "required": ["status"],
            "properties": { "status": { "const": "VERIFIED" } }
          },
          "then": {
            "required": ["verification_method", "verified_at"],
            "properties": {
              "verification_method": { "type": "string", "minLength": 1 },
              "verified_at": { "$ref": "#/$defs/dateTime" },
              "sources": { "minItems": 1 }
            }
          }
        },
        {
          "if": {
            "required": ["publication_status"],
            "properties": { "publication_status": { "enum": ["APPROVED", "PUBLISHED"] } }
          },
          "then": {
            "required": ["human_approval"],
            "properties": { "human_approval": { "$ref": "#/$defs/approval" } }
          }
        },
        {
          "if": {
            "required": ["status"],
            "properties": { "status": { "const": "CORRECTED" } }
          },
          "then": {
            "properties": { "revision_history": { "minItems": 1 } }
          }
        },
        {
          "if": {
            "required": ["status"],
            "properties": { "status": { "const": "DISPUTED" } }
          },
          "then": {
            "properties": { "conflicting_evidence": { "minItems": 1 } }
          }
        }
      ]
    },
    "correctionList": {
      "type": "array",
      "minItems": 1,
      "maxItems": 2000,
      "items": { "$ref": "#/$defs/correction" }
    },
    "correction": {
      "type": "object",
      "additionalProperties": false,
      "required": ["correction_id", "claim_id", "original_statement", "proposed_statement", "reason", "evidence_urls", "status", "revision_history"],
      "properties": {
        "correction_id": { "type": "string", "pattern": "^ART-COR-[0-9]{4,}$" },
        "claim_id": { "type": "string", "pattern": "^ART-EVD-[0-9]{4,}$" },
        "original_statement": { "type": "string", "minLength": 1 },
        "proposed_statement": { "type": "string", "minLength": 1 },
        "reason": { "type": "string", "minLength": 1 },
        "evidence_urls": { "type": "array", "items": { "$ref": "#/$defs/safeUrl" } },
        "status": { "enum": ["SUBMITTED_DRAFT", "UNDER_REVIEW", "NEEDS_EVIDENCE", "ACCEPTED", "DECLINED", "PUBLISHED", "WITHDRAWN"] },
        "submitted_at": { "type": ["string", "null"], "format": "date-time" },
        "reviewed_at": { "type": ["string", "null"], "format": "date-time" },
        "reviewer": { "type": ["string", "null"] },
        "decision_reason": { "type": ["string", "null"] },
        "publication_authorization": { "type": ["object", "null"] },
        "revision_history": { "type": "array", "items": { "$ref": "#/$defs/revision" } },
        "public_note": { "type": "string" }
      },
      "allOf": [
        {
          "if": {
            "required": ["status"],
            "properties": { "status": { "enum": ["ACCEPTED", "PUBLISHED"] } }
          },
          "then": {
            "required": ["publication_authorization"],
            "properties": { "publication_authorization": { "$ref": "#/$defs/approval" } }
          }
        }
      ]
    },
    "exchange": {
      "type": "object",
      "additionalProperties": false,
      "required": ["schema_version", "claims", "corrections"],
      "properties": {
        "schema_version": { "const": "1.1" },
        "claims": { "type": "array", "maxItems": 2000, "items": { "$ref": "#/$defs/record" } },
        "corrections": { "type": "array", "maxItems": 2000, "items": { "$ref": "#/$defs/correction" } },
        "label": { "type": "string" }
      }
    }
  }
}
