{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://civicdataforge.pages.dev/schemas/decision-ready-evidence-v1.schema.json",
  "title": "CivicDataForge decision-ready evidence contract v1",
  "description": "A field-level contract that keeps observed, derived, conflicting and unknown data distinct while binding sources, freshness, rights posture and integrity.",
  "type": "object",
  "additionalProperties": false,
  "required": ["standard_version", "answer", "field_evidence", "source_refs", "conflicts", "unknown_fields", "freshness", "decision_boundary_ref", "contract_receipt_hash"],
  "properties": {
    "standard_version": {"const": "civicdataforge.decision-ready-evidence.v1"},
    "answer": {
      "type": "object",
      "additionalProperties": false,
      "required": ["decision", "meaning", "consequential_use"],
      "properties": {
        "decision": {"enum": ["EVIDENCE_FOUND", "NO_PUBLISHED_MATCH", "REVIEW_REQUIRED", "SOURCE_UNAVAILABLE", "SCOPE_INCOMPLETE"]},
        "meaning": {"type": "string", "minLength": 20},
        "consequential_use": {"const": "REVIEW_SOURCE_BEFORE_ACTION"}
      }
    },
    "field_evidence": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["path", "value_receipt_hash", "presence", "evidence_state", "source_ref", "method_ref", "confidence"],
        "properties": {
          "path": {"type": "string", "minLength": 1},
          "value_receipt_hash": {"type": "string", "pattern": "^sha256:[a-f0-9]{64}$"},
          "presence": {"enum": ["absent", "null", "empty", "value"]},
          "evidence_state": {"enum": ["OBSERVED", "DERIVED", "CONFLICTED", "UNKNOWN"]},
          "source_ref": {"type": "string", "minLength": 1},
          "method_ref": {"type": "string", "minLength": 10},
          "confidence": {"type": "string", "minLength": 3}
        }
      }
    },
    "source_refs": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {"type": "string", "minLength": 1}
    },
    "conflicts": {"type": "array", "items": {"type": "object"}},
    "unknown_fields": {
      "type": "array",
      "uniqueItems": true,
      "items": {"type": "string", "minLength": 1}
    },
    "freshness": {
      "type": "object",
      "additionalProperties": false,
      "required": ["observation_clock", "publisher_clock", "coverage_clock", "status"],
      "properties": {
        "observation_clock": {"type": ["string", "null"], "format": "date-time"},
        "publisher_clock": {"type": ["string", "null"], "format": "date-time"},
        "coverage_clock": {"type": ["string", "null"], "format": "date-time"},
        "status": {"enum": ["OBSERVED_AT_RECORDED", "UNRESOLVED"]}
      }
    },
    "decision_boundary_ref": {"const": "workspace.decision_boundary"},
    "contract_receipt_hash": {"type": "string", "pattern": "^sha256:[a-f0-9]{64}$"}
  }
}
