{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://civicdataforge.pages.dev/schemas/multimodal-evidence-entry-v1.schema.json",
  "title": "CivicDataForge Multimodal Evidence Entry v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "entry_id", "subject", "observations", "fusion_state", "coverage", "receipts"],
  "properties": {
    "schema_version": {"const": "civicdataforge.multimodal-evidence-entry.v1"},
    "entry_id": {"type": "string", "minLength": 1},
    "subject": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "identifiers"],
      "properties": {
        "type": {"enum": ["property", "parcel", "company", "facility", "provider", "vehicle", "farm", "product", "event", "area_of_interest", "other"]},
        "identifiers": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["scheme", "value", "issuer", "match_method"],
            "properties": {
              "scheme": {"type": "string", "minLength": 1},
              "value": {"type": "string", "minLength": 1},
              "issuer": {"type": "string", "minLength": 1},
              "match_method": {"enum": ["exact", "normalized_exact", "geospatial_intersection", "customer_asserted", "reviewed", "candidate"]}
            }
          }
        },
        "geometry": {"type": ["object", "null"]},
        "jurisdiction": {"type": ["string", "null"]}
      }
    },
    "observations": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["observation_id", "layer", "assertion", "publisher", "source", "observed_at", "method", "confidence", "rights", "raw_sha256", "normalized_sha256"],
        "properties": {
          "observation_id": {"type": "string", "minLength": 1},
          "layer": {"enum": ["official_record", "document_extraction", "geospatial_join", "earth_observation", "sensor_telemetry", "historical_change", "customer_supplied", "licensed_source", "derived_indicator"]},
          "assertion": {"type": "string", "minLength": 1},
          "value": {},
          "publisher": {"type": "string", "minLength": 1},
          "source": {"type": "string", "format": "uri"},
          "observed_at": {"type": "string", "format": "date-time"},
          "published_at": {"type": ["string", "null"], "format": "date-time"},
          "coverage_at": {"type": ["string", "null"], "format": "date-time"},
          "method": {"type": "string", "minLength": 1},
          "spatial_resolution_m": {"type": ["number", "null"], "exclusiveMinimum": 0},
          "confidence": {"type": "number", "minimum": 0, "maximum": 1},
          "rights": {"type": "object", "required": ["status", "attribution"], "properties": {"status": {"enum": ["allowed", "licensed", "customer_attested", "restricted", "unresolved"]}, "attribution": {"type": "string"}}, "additionalProperties": true},
          "raw_sha256": {"type": "string", "pattern": "^sha256:[a-f0-9]{64}$"},
          "normalized_sha256": {"type": "string", "pattern": "^sha256:[a-f0-9]{64}$"},
          "limitations": {"type": "array", "items": {"type": "string"}}
        }
      }
    },
    "fusion_state": {"enum": ["CORROBORATED", "COMPLEMENTARY", "CONFLICT_REVIEW_REQUIRED", "UNRESOLVED_IDENTITY", "SOURCE_UNAVAILABLE", "SCOPE_INCOMPLETE"]},
    "coverage": {
      "type": "object",
      "additionalProperties": false,
      "required": ["complete_for_declared_scope", "declared_scope", "missing_layers"],
      "properties": {
        "complete_for_declared_scope": {"type": "boolean"},
        "declared_scope": {"type": "string", "minLength": 1},
        "missing_layers": {"type": "array", "items": {"type": "string"}},
        "next_refresh_at": {"type": ["string", "null"], "format": "date-time"}
      }
    },
    "conflicts": {"type": "array", "items": {"type": "object"}},
    "receipts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["entry_sha256", "run_sha256"],
      "properties": {
        "entry_sha256": {"type": "string", "pattern": "^sha256:[a-f0-9]{64}$"},
        "run_sha256": {"type": "string", "pattern": "^sha256:[a-f0-9]{64}$"}
      }
    }
  }
}
