{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://palimpsest.info/protocol/bri-economic-observations-v1.schema.json",
  "title": "Palimpsest BRI national economic observations v1",
  "description": "A bounded bundle of aggregate World Bank WDI observations for China, Myanmar, and Pakistan. National context is not evidence of BRI project attribution or causality.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "collection_id",
    "generated_at",
    "context_policy",
    "source",
    "registry_sha256",
    "coverage",
    "request_receipts",
    "observations_sha256",
    "observations"
  ],
  "properties": {
    "schema_version": {"const": "palimpsest.bri-economic-observations.v1"},
    "collection_id": {"$ref": "#/$defs/sha256"},
    "generated_at": {"$ref": "#/$defs/timestamp"},
    "context_policy": {"$ref": "#/$defs/contextPolicy"},
    "source": {"$ref": "#/$defs/source"},
    "registry_sha256": {"$ref": "#/$defs/sha256"},
    "coverage": {"$ref": "#/$defs/coverage"},
    "request_receipts": {
      "type": "array",
      "minItems": 1,
      "maxItems": 1,
      "items": {"$ref": "#/$defs/requestReceipt"}
    },
    "observations_sha256": {"$ref": "#/$defs/sha256"},
    "observations": {
      "type": "array",
      "minItems": 1,
      "maxItems": 12000,
      "items": {"$ref": "#/$defs/observation"}
    }
  },
  "$defs": {
    "sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "nonblank": {
      "type": "string",
      "minLength": 1,
      "maxLength": 4096,
      "pattern": ".*\\S.*"
    },
    "date": {
      "type": "string",
      "format": "date",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "timestamp": {
      "type": "string",
      "format": "date-time",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{1,6})?Z$"
    },
    "apiUrl": {
      "type": "string",
      "format": "uri",
      "maxLength": 16384,
      "pattern": "^https://api\\.worldbank\\.org/v2/country/CHN;MMR;PAK/indicator/"
    },
    "rights": {
      "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"}
      }
    },
    "contextPolicy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "scope",
        "aggregate_level",
        "countries",
        "causality_boundary",
        "actor_inference",
        "project_attribution",
        "tactical_data",
        "missing_value_policy",
        "forecast_policy",
        "qualification_policy",
        "downstream_semantics"
      ],
      "properties": {
        "scope": {"const": "national_economic_context"},
        "aggregate_level": {"const": "country"},
        "countries": {
          "const": ["CHN", "MMR", "PAK"]
        },
        "causality_boundary": {"const": "not_evidence_of_bri_causality"},
        "actor_inference": {"const": "prohibited"},
        "project_attribution": {"const": "prohibited"},
        "tactical_data": {"const": "prohibited"},
        "missing_value_policy": {"const": "source_null_remains_unavailable"},
        "forecast_policy": {"const": "source_obs_status_F_remains_forecast"},
        "qualification_policy": {"const": "obs_status_footnote_scale_preserved_verbatim"},
        "downstream_semantics": {
          "type": "object",
          "additionalProperties": false,
          "required": ["observed", "forecast", "unavailable", "join_boundary"],
          "properties": {
            "observed": {"const": "numeric_source_value_without_forecast_marker"},
            "forecast": {"const": "numeric_source_value_marked_F_not_observed"},
            "unavailable": {"const": "source_null_not_zero_or_imputed"},
            "join_boundary": {"const": "country_period_context_only_no_project_actor_or_causal_join"}
          }
        }
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_id",
        "name",
        "publisher",
        "catalog_url",
        "license",
        "license_url",
        "attribution",
        "redistribution_status",
        "rights_evidence_url",
        "indicator_provenance_boundary"
      ],
      "properties": {
        "source_id": {"const": "world_bank_wdi"},
        "name": {"const": "World Development Indicators"},
        "publisher": {"const": "World Bank"},
        "catalog_url": {"const": "https://datacatalog.worldbank.org/search/dataset/0037712/world-development-indicators"},
        "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"},
        "indicator_provenance_boundary": {"$ref": "#/$defs/nonblank"}
      }
    },
    "coverage": {
      "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": 1960, "maximum": 2100},
        "end_year": {"type": "integer", "minimum": 1960, "maximum": 2100},
        "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}
      }
    },
    "requestReceipt": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "acquisition_id",
        "request_id",
        "evidence_url",
        "raw_response_sha256",
        "response_bytes",
        "source_rows",
        "observed_rows",
        "forecast_rows",
        "unavailable_rows",
        "dataset_last_updated",
        "source_release_upper_bound",
        "retrieved_at"
      ],
      "properties": {
        "acquisition_id": {"$ref": "#/$defs/sha256"},
        "request_id": {"$ref": "#/$defs/sha256"},
        "evidence_url": {"$ref": "#/$defs/apiUrl"},
        "raw_response_sha256": {"$ref": "#/$defs/sha256"},
        "response_bytes": {"type": "integer", "minimum": 1, "maximum": 12582912},
        "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},
        "dataset_last_updated": {"$ref": "#/$defs/date"},
        "source_release_upper_bound": {"$ref": "#/$defs/timestamp"},
        "retrieved_at": {"$ref": "#/$defs/timestamp"}
      }
    },
    "observation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schema_version",
        "series_id",
        "indicator_id",
        "country_code",
        "value",
        "unit",
        "evidence_state",
        "unavailability_reason",
        "obs_status",
        "footnote",
        "scale",
        "frequency",
        "aggregate_level",
        "period_start",
        "period_end",
        "source_release_upper_bound",
        "retrieved_at",
        "source_dataset_last_updated",
        "source_id",
        "publisher",
        "evidence_url",
        "raw_response_sha256",
        "source_row_sha256",
        "request_id",
        "acquisition_id",
        "context_scope",
        "causality_boundary",
        "release_time_semantics",
        "rights",
        "observation_id"
      ],
      "properties": {
        "schema_version": {"const": "palimpsest.bri-economic-observation.v1"},
        "series_id": {
          "type": "string",
          "pattern": "^bri\\.context\\.wdi\\.[a-z0-9][a-z0-9_]{1,119}$"
        },
        "indicator_id": {
          "type": "string",
          "pattern": "^[A-Z0-9][A-Z0-9._-]{1,79}$"
        },
        "country_code": {"enum": ["CHN", "MMR", "PAK"]},
        "value": {"type": ["number", "null"]},
        "unit": {"$ref": "#/$defs/nonblank"},
        "evidence_state": {"enum": ["observed", "forecast", "unavailable"]},
        "unavailability_reason": {
          "oneOf": [
            {"type": "null"},
            {"const": "source_value_null"}
          ]
        },
        "obs_status": {"enum": ["", "F"]},
        "footnote": {"type": "string", "maxLength": 4096},
        "scale": {"type": "string", "maxLength": 4096},
        "frequency": {"const": "A"},
        "aggregate_level": {"const": "country"},
        "period_start": {"$ref": "#/$defs/date"},
        "period_end": {"$ref": "#/$defs/date"},
        "source_release_upper_bound": {"$ref": "#/$defs/timestamp"},
        "retrieved_at": {"$ref": "#/$defs/timestamp"},
        "source_dataset_last_updated": {"$ref": "#/$defs/date"},
        "source_id": {"const": "world_bank_wdi"},
        "publisher": {"const": "World Bank"},
        "evidence_url": {"$ref": "#/$defs/apiUrl"},
        "raw_response_sha256": {"$ref": "#/$defs/sha256"},
        "source_row_sha256": {"$ref": "#/$defs/sha256"},
        "request_id": {"$ref": "#/$defs/sha256"},
        "acquisition_id": {"$ref": "#/$defs/sha256"},
        "context_scope": {"const": "national_economic_context"},
        "causality_boundary": {"const": "not_evidence_of_bri_causality"},
        "release_time_semantics": {"const": "dataset_lastupdated_upper_bound"},
        "rights": {"$ref": "#/$defs/rights"},
        "observation_id": {"$ref": "#/$defs/sha256"}
      },
      "allOf": [
        {
          "if": {
            "properties": {"evidence_state": {"const": "observed"}},
            "required": ["evidence_state"]
          },
          "then": {
            "properties": {
              "value": {"type": "number"},
              "unavailability_reason": {"type": "null"},
              "obs_status": {"const": ""}
            }
          }
        },
        {
          "if": {
            "properties": {"evidence_state": {"const": "forecast"}},
            "required": ["evidence_state"]
          },
          "then": {
            "properties": {
              "value": {"type": "number"},
              "unavailability_reason": {"type": "null"},
              "obs_status": {"const": "F"}
            }
          }
        },
        {
          "if": {
            "properties": {"evidence_state": {"const": "unavailable"}},
            "required": ["evidence_state"]
          },
          "then": {
            "properties": {
              "value": {"type": "null"},
              "unavailability_reason": {"const": "source_value_null"},
              "obs_status": {"const": ""}
            }
          }
        }
      ]
    }
  }
}
