{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://palimpsest.info/protocol/belt-and-road-observatory-v2.schema.json",
  "title": "Palimpsest Belt and Road Observatory coverage and observation contract",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "$schema",
    "schema_version",
    "as_of",
    "scope",
    "publication_policy",
    "coverage_report",
    "project_fields",
    "economic_metrics",
    "local_impact_fields",
    "movement_taxonomy",
    "geographies",
    "workstreams",
    "watch_targets",
    "partner_bridges",
    "sources",
    "prioritized_backlog",
    "interpretation",
    "observation_datasets"
  ],
  "properties": {
    "$schema": { "const": "/protocol/belt-and-road-observatory-v2.schema.json" },
    "schema_version": { "const": "palimpsest.belt-and-road-observatory.v2" },
    "as_of": { "type": "string", "format": "date-time" },
    "scope": { "type": "string", "minLength": 20 },
    "publication_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "project_total_rule",
        "claim_join_rule",
        "money_rule",
        "status_rule",
        "conflict_location_grain",
        "conflict_publication_delay_days",
        "person_level_dossiers",
        "tactical_vulnerability_analysis",
        "correction_channel",
        "minimum_project_corroboration"
      ],
      "properties": {
        "project_total_rule": { "const": "never_mix_lifecycle_states" },
        "claim_join_rule": { "const": "same_project_identity_and_compatible_claim_semantics_only" },
        "money_rule": { "type": "string", "minLength": 1 },
        "status_rule": { "type": "string", "minLength": 1 },
        "conflict_location_grain": { "const": "delayed_administrative_area_only" },
        "conflict_publication_delay_days": { "type": "integer", "minimum": 30 },
        "person_level_dossiers": { "const": "prohibited" },
        "tactical_vulnerability_analysis": { "const": "prohibited" },
        "correction_channel": { "type": "string", "minLength": 1 },
        "minimum_project_corroboration": { "type": "string", "minLength": 1 }
      }
    },
    "coverage_report": { "$ref": "#/$defs/coverageReport" },
    "project_fields": { "$ref": "#/$defs/nonemptyUniqueStrings" },
    "economic_metrics": { "$ref": "#/$defs/nonemptyUniqueStrings" },
    "local_impact_fields": { "$ref": "#/$defs/nonemptyUniqueStrings" },
    "movement_taxonomy": { "$ref": "#/$defs/movementTaxonomy" },
    "geographies": {
      "type": "array",
      "minItems": 7,
      "items": { "$ref": "#/$defs/geography" }
    },
    "workstreams": {
      "type": "array",
      "minItems": 5,
      "items": { "$ref": "#/$defs/workstream" }
    },
    "watch_targets": {
      "type": "array",
      "minItems": 10,
      "items": { "$ref": "#/$defs/watchTarget" }
    },
    "partner_bridges": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/partnerBridge" }
    },
    "sources": {
      "type": "array",
      "minItems": 30,
      "items": { "$ref": "#/$defs/source" }
    },
    "prioritized_backlog": {
      "type": "array",
      "items": { "$ref": "#/$defs/backlogItem" }
    },
    "interpretation": {
      "type": "array",
      "minItems": 4,
      "items": { "type": "string", "minLength": 1 },
      "uniqueItems": true
    },
    "observation_datasets": {
      "type": "array",
      "minItems": 1,
      "maxItems": 1,
      "items": { "$ref": "#/$defs/observationDataset" }
    }
  },
  "$defs": {
    "nonemptyUniqueStrings": {
      "type": "array",
      "minItems": 1,
      "items": { "type": "string", "minLength": 1 },
      "uniqueItems": true
    },
    "uniqueStrings": {
      "type": "array",
      "items": { "type": "string", "minLength": 1 },
      "uniqueItems": true
    },
    "coverageReport": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_count",
        "implementation_states",
        "source_classes",
        "build_ready_source_count",
        "coverage",
        "geographies",
        "build_ready_gaps"
      ],
      "properties": {
        "source_count": { "type": "integer", "minimum": 30 },
        "implementation_states": { "type": "object", "additionalProperties": { "type": "integer", "minimum": 0 } },
        "source_classes": { "type": "object", "additionalProperties": { "type": "integer", "minimum": 0 } },
        "build_ready_source_count": { "type": "integer", "minimum": 1 },
        "coverage": { "type": "object", "additionalProperties": { "$ref": "#/$defs/coverageCell" } },
        "geographies": { "type": "object", "additionalProperties": { "$ref": "#/$defs/geographyCoverage" } },
        "build_ready_gaps": { "$ref": "#/$defs/uniqueStrings" }
      }
    },
    "coverageCell": {
      "type": "object",
      "additionalProperties": false,
      "required": ["sources", "independent_groups", "build_ready_sources", "build_ready_independent_groups", "source_ids"],
      "properties": {
        "sources": { "type": "integer", "minimum": 0 },
        "independent_groups": { "type": "integer", "minimum": 0 },
        "build_ready_sources": { "type": "integer", "minimum": 0 },
        "build_ready_independent_groups": { "type": "integer", "minimum": 0 },
        "source_ids": { "type": "array", "items": { "type": "string" }, "uniqueItems": true }
      }
    },
    "geographyCoverage": {
      "type": "object",
      "additionalProperties": false,
      "required": ["sources", "independent_groups", "source_ids"],
      "properties": {
        "sources": { "type": "integer", "minimum": 0 },
        "independent_groups": { "type": "integer", "minimum": 0 },
        "source_ids": { "type": "array", "items": { "type": "string" }, "uniqueItems": true }
      }
    },
    "movementTaxonomy": {
      "type": "object",
      "additionalProperties": false,
      "required": ["umbrella_term", "umbrella_term_policy", "identity_rule", "lanes"],
      "properties": {
        "umbrella_term": { "const": "Balochistan liberation movement" },
        "umbrella_term_policy": { "const": "concept_only_never_single_actor" },
        "identity_rule": { "type": "string", "minLength": 1 },
        "lanes": { "type": "array", "minItems": 7, "items": { "$ref": "#/$defs/movementLane" } }
      }
    },
    "movementLane": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lane_id", "label", "entity_types", "claim_types", "prohibited_merges"],
      "properties": {
        "lane_id": { "type": "string", "minLength": 1 },
        "label": { "type": "string", "minLength": 1 },
        "entity_types": { "$ref": "#/$defs/nonemptyUniqueStrings" },
        "claim_types": { "$ref": "#/$defs/nonemptyUniqueStrings" },
        "prohibited_merges": { "$ref": "#/$defs/nonemptyUniqueStrings" }
      }
    },
    "geography": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "kind", "parent", "priority"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "label": { "type": "string", "minLength": 1 },
        "kind": { "enum": ["global", "country", "admin1", "admin2"] },
        "parent": { "type": ["string", "null"] },
        "priority": { "type": "integer", "minimum": 1, "maximum": 10 }
      }
    },
    "workstream": {
      "type": "object",
      "additionalProperties": false,
      "required": ["workstream_id", "label", "status", "required_coverage", "source_ids"],
      "properties": {
        "workstream_id": { "type": "string", "minLength": 1 },
        "label": { "type": "string", "minLength": 1 },
        "status": { "type": "string", "minLength": 1 },
        "required_coverage": { "$ref": "#/$defs/nonemptyUniqueStrings" },
        "source_ids": { "$ref": "#/$defs/nonemptyUniqueStrings" }
      }
    },
    "watchTarget": {
      "type": "object",
      "additionalProperties": false,
      "required": ["target_id", "label", "target_type", "evidence_status", "required_coverage", "source_ids"],
      "properties": {
        "target_id": { "type": "string", "minLength": 1 },
        "label": { "type": "string", "minLength": 1 },
        "target_type": { "type": "string", "minLength": 1 },
        "evidence_status": { "type": "string", "minLength": 1 },
        "required_coverage": { "$ref": "#/$defs/nonemptyUniqueStrings" },
        "source_ids": { "$ref": "#/$defs/nonemptyUniqueStrings" }
      }
    },
    "partnerBridge": {
      "type": "object",
      "additionalProperties": false,
      "required": ["partner", "contract", "artifact_id", "status", "producer_path", "palimpsest_path", "join_policy", "actor_inference", "claim_boundary"],
      "properties": {
        "partner": { "const": "NarcoScope" },
        "contract": { "const": "narcoscope.palimpsest.corridor-aggregate.v2" },
        "artifact_id": { "const": "narcoscope.china-pakistan-myanmar.official-coverage" },
        "status": { "enum": ["repository_ready_not_deployed", "production_verified"] },
        "producer_path": { "type": "string", "minLength": 1 },
        "palimpsest_path": { "type": "string", "minLength": 1 },
        "join_policy": { "const": "geography_and_time_only" },
        "actor_inference": { "const": "prohibited" },
        "claim_boundary": { "type": "string", "minLength": 1 }
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": ["source_id", "name", "publisher", "url", "source_class", "authority_role", "access_mode", "rights_status", "implementation", "cadence", "geographies", "coverage", "independence_group", "claim_classes", "notes"],
      "properties": {
        "source_id": { "type": "string", "pattern": "^[a-z][a-z0-9_]{1,79}$" },
        "name": { "type": "string", "minLength": 1 },
        "publisher": { "type": "string", "minLength": 1 },
        "url": { "type": "string", "format": "uri" },
        "source_class": { "enum": ["official_china", "official_host", "multilateral", "research", "civil_society", "legal", "partner"] },
        "authority_role": { "enum": ["primary_record", "administrative_position", "independent_observation", "analytical_estimate", "legal_instrument", "partner_aggregate"] },
        "access_mode": { "enum": ["open_download", "open_keyless", "public_manual", "registration", "licensed", "restricted"] },
        "rights_status": { "enum": ["public_domain", "attribution", "open_reuse", "official_publication_review_required", "link_only_pending_review", "licensed_no_redistribution"] },
        "implementation": { "enum": ["live", "adapter_ready", "planned", "link_only", "blocked", "out_of_scope", "repository_ready"] },
        "cadence": { "enum": ["event", "daily", "weekly", "monthly", "quarterly", "annual", "irregular", "snapshot"] },
        "geographies": { "$ref": "#/$defs/nonemptyUniqueStrings" },
        "coverage": { "$ref": "#/$defs/nonemptyUniqueStrings" },
        "independence_group": { "type": "string", "minLength": 1 },
        "claim_classes": { "$ref": "#/$defs/nonemptyUniqueStrings" },
        "notes": { "type": "string", "minLength": 1 }
      }
    },
    "observationDataset": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "dataset_id",
        "source_id",
        "implementation_state",
        "publication_state",
        "artifact",
        "observation_schema",
        "series_registry",
        "collection_id",
        "generated_at",
        "coverage",
        "clocks",
        "rights",
        "context_boundary",
        "publication_receipt"
      ],
      "properties": {
        "dataset_id": {"const": "bri-economic-context-world-bank-wdi"},
        "source_id": {"const": "world_bank_wdi"},
        "implementation_state": {"enum": ["adapter_ready", "repository_ready"]},
        "publication_state": {"const": "repository_ready_not_deployed"},
        "artifact": {"$ref": "#/$defs/artifactLocator"},
        "observation_schema": {"$ref": "#/$defs/contractLocator"},
        "series_registry": {"$ref": "#/$defs/contractLocator"},
        "collection_id": {"$ref": "#/$defs/sha256"},
        "generated_at": {"type": "string", "format": "date-time"},
        "coverage": {"$ref": "#/$defs/observationCoverage"},
        "clocks": {"$ref": "#/$defs/observationClocks"},
        "rights": {"$ref": "#/$defs/wdiRights"},
        "context_boundary": {"$ref": "#/$defs/contextBoundary"},
        "publication_receipt": {"type": "null"}
      }
    },
    "artifactLocator": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "url", "media_type", "bytes", "sha256"],
      "properties": {
        "path": {"const": "readings/bri-economic-observations-latest.json"},
        "url": {"const": "https://palimpsest.info/readings/bri-economic-observations-latest.json"},
        "media_type": {"const": "application/json"},
        "bytes": {"type": "integer", "minimum": 1, "maximum": 134217728},
        "sha256": {"$ref": "#/$defs/sha256"}
      }
    },
    "contractLocator": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "url", "sha256"],
      "properties": {
        "path": {
          "enum": [
            "protocol/bri-economic-observations-v1.schema.json",
            "config/bri_wdi_series.json"
          ]
        },
        "url": {"type": "string", "format": "uri"},
        "sha256": {"$ref": "#/$defs/sha256"}
      }
    },
    "observationCoverage": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "start_year",
        "end_year",
        "countries",
        "indicators",
        "source_rows",
        "observed_rows",
        "forecast_rows",
        "unavailable_rows"
      ],
      "properties": {
        "start_year": {"type": "integer", "minimum": 1900, "maximum": 2200},
        "end_year": {"type": "integer", "minimum": 1900, "maximum": 2200},
        "countries": {"const": 3},
        "indicators": {"type": "integer", "minimum": 1, "maximum": 24},
        "source_rows": {"type": "integer", "minimum": 1, "maximum": 12000},
        "observed_rows": {"type": "integer", "minimum": 0, "maximum": 12000},
        "forecast_rows": {"type": "integer", "minimum": 0, "maximum": 12000},
        "unavailable_rows": {"type": "integer", "minimum": 0, "maximum": 12000}
      }
    },
    "observationClocks": {
      "type": "object",
      "additionalProperties": false,
      "required": ["dataset_last_updated", "source_release_upper_bound", "retrieved_at"],
      "properties": {
        "dataset_last_updated": {"type": "string", "format": "date"},
        "source_release_upper_bound": {"type": "string", "format": "date-time"},
        "retrieved_at": {"type": "string", "format": "date-time"}
      }
    },
    "wdiRights": {
      "type": "object",
      "additionalProperties": false,
      "required": ["license", "license_url", "attribution", "redistribution_status", "rights_evidence_url"],
      "properties": {
        "license": {"const": "CC-BY-4.0"},
        "license_url": {"const": "https://creativecommons.org/licenses/by/4.0/"},
        "attribution": {"const": "World Bank, World Development Indicators"},
        "redistribution_status": {"const": "allowed_with_attribution"},
        "rights_evidence_url": {"const": "https://datacatalog.worldbank.org/search/dataset/0037712/world-development-indicators"}
      }
    },
    "contextBoundary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "allowed_role",
        "join_scope",
        "project_inference",
        "actor_inference",
        "corridor_inference",
        "causal_inference",
        "tactical_data",
        "missing_value_policy",
        "forecast_policy"
      ],
      "properties": {
        "allowed_role": {"const": "context"},
        "join_scope": {"const": "country_period_only"},
        "project_inference": {"const": "prohibited"},
        "actor_inference": {"const": "prohibited"},
        "corridor_inference": {"const": "prohibited"},
        "causal_inference": {"const": "prohibited"},
        "tactical_data": {"const": "prohibited"},
        "missing_value_policy": {"const": "source_null_remains_unavailable"},
        "forecast_policy": {"const": "source_obs_status_F_remains_forecast"}
      }
    },
    "sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "backlogItem": {
      "type": "object",
      "additionalProperties": false,
      "required": ["source_id", "name", "priority_score", "ground_level_adjustment", "rights_status", "geographies", "coverage", "next_gate"],
      "properties": {
        "source_id": { "type": "string", "minLength": 1 },
        "name": { "type": "string", "minLength": 1 },
        "priority_score": { "type": "number" },
        "ground_level_adjustment": { "type": "number", "minimum": 0 },
        "rights_status": { "type": "string", "minLength": 1 },
        "geographies": { "$ref": "#/$defs/nonemptyUniqueStrings" },
        "coverage": { "$ref": "#/$defs/nonemptyUniqueStrings" },
        "next_gate": { "enum": ["rights_review", "adapter_implementation"] }
      }
    }
  }
}
