{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://jaredmodstorage.github.io/schemas/facility-observation-coverage.schema.json",
  "title": "Facility Observation Coverage Contract",
  "description": "Structural schema for one evidence-bounded facility observation coverage record. Conformance does not establish truth, source fitness, authority, coverage, privacy compliance, safety, deployment, or decision admissibility.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "coverage_contract_id",
    "fictional",
    "question",
    "claim",
    "observation_paths",
    "decision_gate",
    "privacy",
    "evidence_boundary"
  ],
  "$defs": {
    "identity": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
    },
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "duration": {
      "type": "string",
      "pattern": "^P(?!$).+"
    },
    "blindSpot": {
      "enum": [
        "spatial",
        "temporal",
        "semantic",
        "identity",
        "transport",
        "quality",
        "common_mode",
        "authority",
        "intentional_privacy"
      ]
    }
  },
  "properties": {
    "schema_version": { "const": "1.0.0" },
    "coverage_contract_id": { "$ref": "#/$defs/identity" },
    "fictional": { "const": true },
    "question": {
      "type": "object",
      "additionalProperties": false,
      "required": ["question_id", "facility_id", "decision_use", "consequence_class", "evaluated_at"],
      "properties": {
        "question_id": { "$ref": "#/$defs/identity" },
        "facility_id": { "$ref": "#/$defs/identity" },
        "decision_use": { "type": "string", "minLength": 10 },
        "consequence_class": { "enum": ["C0_informational", "C1_bounded_operational", "C2_material_operational", "C3_high_consequence"] },
        "evaluated_at": { "$ref": "#/$defs/timestamp" }
      }
    },
    "claim": {
      "type": "object",
      "additionalProperties": false,
      "required": ["claim_id", "text", "mode", "target_scope", "property", "spatial_footprint", "population_denominator"],
      "properties": {
        "claim_id": { "$ref": "#/$defs/identity" },
        "text": { "type": "string", "minLength": 10 },
        "mode": { "enum": ["directly_observed", "derived", "inferred", "declared", "unknown"] },
        "target_scope": { "type": "string", "minLength": 1 },
        "property": { "type": "string", "minLength": 1 },
        "spatial_footprint": { "type": "string", "minLength": 1 },
        "population_denominator": { "type": "string", "minLength": 1 }
      }
    },
    "observation_paths": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "path_id",
          "source_id",
          "source_owner",
          "source_lifecycle",
          "acquisition_mode",
          "sampling_or_trigger",
          "source_time",
          "observed_at",
          "received_at",
          "freshness_limit",
          "allowed_lateness",
          "expected_continuity",
          "gap_detection",
          "transport_semantics",
          "queue_or_overflow",
          "unit_or_encoding",
          "native_quality",
          "common_mode_dependencies",
          "blind_spots"
        ],
        "properties": {
          "path_id": { "$ref": "#/$defs/identity" },
          "source_id": { "$ref": "#/$defs/identity" },
          "source_owner": { "$ref": "#/$defs/identity" },
          "source_lifecycle": { "enum": ["active", "retired", "unknown", "intentionally_uninstrumented"] },
          "acquisition_mode": { "enum": ["event_driven", "polled", "streamed", "batch_window", "human_procedure", "none"] },
          "sampling_or_trigger": { "type": "string", "minLength": 1 },
          "change_filter": { "type": ["string", "null"] },
          "source_time": { "$ref": "#/$defs/timestamp" },
          "observed_at": { "$ref": "#/$defs/timestamp" },
          "received_at": { "$ref": "#/$defs/timestamp" },
          "freshness_limit": { "$ref": "#/$defs/duration" },
          "allowed_lateness": { "$ref": "#/$defs/duration" },
          "expected_continuity": { "type": "string", "minLength": 1 },
          "gap_detection": { "type": "string", "minLength": 1 },
          "transport_semantics": { "type": "string", "minLength": 1 },
          "queue_or_overflow": { "type": "string", "minLength": 1 },
          "unit_or_encoding": { "type": "string", "minLength": 1 },
          "native_quality": { "enum": ["good", "uncertain", "bad", "unknown", "declared"] },
          "transformation_id": { "oneOf": [{ "$ref": "#/$defs/identity" }, { "type": "null" }] },
          "corroborating_source": { "oneOf": [{ "$ref": "#/$defs/identity" }, { "type": "null" }] },
          "common_mode_dependencies": {
            "type": "array",
            "items": { "type": "string", "minLength": 1 },
            "uniqueItems": true
          },
          "blind_spots": {
            "type": "array",
            "items": { "$ref": "#/$defs/blindSpot" },
            "uniqueItems": true
          }
        }
      }
    },
    "decision_gate": {
      "type": "object",
      "additionalProperties": false,
      "required": ["coverage_state", "admission_rule", "prohibited_promotions", "degradation_rule", "exception_owner"],
      "properties": {
        "coverage_state": { "enum": ["C0_uninstrumented", "C1_signal_present", "C2_bounded_observation", "C3_decision_admissible", "C4_corroborated", "CX_indeterminate"] },
        "admission_rule": { "type": "string", "minLength": 20 },
        "prohibited_promotions": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "minLength": 5 },
          "uniqueItems": true
        },
        "degradation_rule": { "type": "string", "minLength": 20 },
        "exception_owner": { "$ref": "#/$defs/identity" }
      }
    },
    "privacy": {
      "type": "object",
      "additionalProperties": false,
      "required": ["purpose", "allowed_audience", "retention_rule", "intentional_gaps"],
      "properties": {
        "purpose": { "type": "string", "minLength": 10 },
        "allowed_audience": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/$defs/identity" },
          "uniqueItems": true
        },
        "retention_rule": { "type": "string", "minLength": 10 },
        "intentional_gaps": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        }
      }
    },
    "evidence_boundary": { "type": "string", "minLength": 80 }
  }
}
