{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://henok.online/schemas/africa-intelligence-data-engine-v1.json",
  "title": "Africa Intelligence Data Engine V1 Dataset",
  "type": "object",
  "additionalProperties": false,
  "required": ["release", "geographies", "countries", "entities", "sources", "indicators", "projects", "events", "observations", "reviewDecisions"],
  "properties": {
    "release": { "$ref": "#/$defs/release" },
    "geographies": { "type": "array", "items": { "$ref": "#/$defs/geography" } },
    "countries": { "type": "array", "items": { "$ref": "#/$defs/country" } },
    "entities": { "type": "array", "items": { "$ref": "#/$defs/entity" } },
    "sources": { "type": "array", "items": { "$ref": "#/$defs/source" } },
    "indicators": { "type": "array", "items": { "$ref": "#/$defs/indicator" } },
    "projects": { "type": "array", "items": { "$ref": "#/$defs/project" } },
    "events": { "type": "array", "items": { "$ref": "#/$defs/event" } },
    "observations": { "type": "array", "items": { "$ref": "#/$defs/observation" } },
    "reviewDecisions": { "type": "array", "items": { "$ref": "#/$defs/review" } }
  },
  "$defs": {
    "id": { "type": "string", "minLength": 3, "pattern": "^[a-z0-9][a-z0-9-]*$" },
    "dateOrNull": { "type": ["string", "null"], "pattern": "^[0-9]{4}(-[0-9]{2})?(-[0-9]{2})?$" },
    "claimStatus": { "enum": ["VERIFIED", "OPERATIONAL", "ANNOUNCED", "PLANNED", "ESTIMATED", "DISPUTED", "UNAVAILABLE"] },
    "confidence": { "enum": ["HIGH", "MEDIUM", "LOW", "INSUFFICIENT"] },
    "release": {
      "type": "object",
      "required": ["id", "phase", "compiledAt", "evidenceCutoff", "status", "rankingEnabled", "rankingReason"],
      "properties": {
        "id": { "type": "string" }, "phase": { "const": 1 }, "title": { "type": "string" },
        "compiledAt": { "type": "string" }, "evidenceCutoff": { "type": "string", "format": "date" },
        "previousEvidenceReview": { "type": "string", "format": "date" },
        "status": { "enum": ["VALIDATION_CANDIDATE", "VALIDATED", "SUPERSEDED"] },
        "rankingEnabled": { "type": "boolean" }, "rankingReason": { "type": "string", "minLength": 1 },
        "licenseNote": { "type": "string" }
      }
    },
    "geography": {
      "type": "object", "additionalProperties": false,
      "required": ["id", "type", "name", "m49", "parentId"],
      "properties": { "id": { "$ref": "#/$defs/id" }, "type": { "enum": ["WORLD", "REGION", "COUNTRY", "SUBNATIONAL"] }, "name": { "type": "string" }, "m49": { "type": ["string", "null"], "pattern": "^[0-9]{3}$" }, "parentId": { "type": ["string", "null"] } }
    },
    "country": {
      "type": "object", "additionalProperties": false,
      "required": ["geographyId", "iso2", "iso3", "officialName", "indexOrder"],
      "properties": { "geographyId": { "type": "string" }, "iso2": { "type": "string", "pattern": "^[A-Z]{2}$" }, "iso3": { "type": "string", "pattern": "^[A-Z]{3}$" }, "officialName": { "type": "string" }, "indexOrder": { "type": "integer", "minimum": 1 } }
    },
    "entity": {
      "type": "object", "additionalProperties": false,
      "required": ["id", "name", "type", "countryGeographyId", "website"],
      "properties": { "id": { "$ref": "#/$defs/id" }, "name": { "type": "string" }, "type": { "type": "string" }, "countryGeographyId": { "type": ["string", "null"] }, "website": { "type": ["string", "null"], "format": "uri" } }
    },
    "source": {
      "type": "object", "additionalProperties": false,
      "required": ["id", "publisherEntityId", "title", "url", "publishedAt", "publishedPrecision", "firstAccessedAt", "lastCheckedAt", "sourceClass", "legacyEvidenceClass", "retrievalStatus", "language"],
      "properties": {
        "id": { "$ref": "#/$defs/id" }, "publisherEntityId": { "type": "string" }, "title": { "type": "string" },
        "url": { "type": "string", "format": "uri" }, "publishedAt": { "$ref": "#/$defs/dateOrNull" },
        "publishedPrecision": { "enum": ["DAY", "MONTH", "YEAR", "CURRENT", "UNKNOWN"] },
        "firstAccessedAt": { "type": "string", "format": "date" }, "lastCheckedAt": { "type": "string", "format": "date" },
        "sourceClass": { "enum": ["OFFICIAL_DATA", "OFFICIAL_INVENTORY", "COMPANY_ANNOUNCEMENT", "INDUSTRY_AGGREGATION", "SECONDARY_REPORT", "REFERENCE_DATASET"] },
        "legacyEvidenceClass": { "enum": ["measured", "officially-announced", "secondary-report", "unavailable"] },
        "retrievalStatus": { "enum": ["REACHABLE", "BLOCKED_ON_RECHECK", "CARRIED_FORWARD", "ARCHIVED", "BROKEN"] },
        "language": { "type": "string" }, "notes": { "type": "string" }
      }
    },
    "indicator": {
      "type": "object", "additionalProperties": false,
      "required": ["id", "slug", "name", "domain", "dataType", "unit", "scope", "comparable", "definition", "methodologyVersion"],
      "properties": { "id": { "$ref": "#/$defs/id" }, "slug": { "type": "string" }, "name": { "type": "string" }, "domain": { "type": "string" }, "dataType": { "enum": ["INTEGER", "DECIMAL", "TEXT", "BOOLEAN", "ORDINAL"] }, "unit": { "type": "string" }, "scope": { "enum": ["WORLD", "REGION", "COUNTRY", "SUBNATIONAL"] }, "comparable": { "type": "boolean" }, "definition": { "type": "string" }, "methodologyVersion": { "type": "string" } }
    },
    "evidence": {
      "type": "object", "additionalProperties": false,
      "required": ["sourceId", "role"],
      "properties": { "sourceId": { "type": "string" }, "role": { "enum": ["SUPPORTS", "CONTRADICTS", "CONTEXT", "METHODOLOGY"] }, "locator": { "type": "string" } }
    },
    "observation": {
      "type": "object",
      "required": ["id", "geographyId", "indicatorId", "periodStart", "periodEnd", "recordedAt", "valueState", "unit", "valueModifier", "claimStatus", "confidence", "lifecycleStage", "comparability", "evidence"],
      "properties": {
        "id": { "$ref": "#/$defs/id" }, "geographyId": { "type": "string" }, "indicatorId": { "type": "string" },
        "periodStart": { "$ref": "#/$defs/dateOrNull" }, "periodEnd": { "$ref": "#/$defs/dateOrNull" }, "recordedAt": { "type": "string" },
        "valueState": { "enum": ["OBSERVED", "SOURCED_ZERO", "MISSING"] }, "valueNumeric": { "type": "number" }, "valueText": { "type": "string" }, "valueBoolean": { "type": "boolean" },
        "unit": { "type": "string" }, "valueModifier": { "enum": ["EXACT", "APPROXIMATE", "GREATER_THAN", "LESS_THAN", "UP_TO", "NOT_APPLICABLE"] },
        "claimStatus": { "$ref": "#/$defs/claimStatus" }, "confidence": { "$ref": "#/$defs/confidence" },
        "lifecycleStage": { "enum": ["OPERATIONAL", "DEPLOYING", "UNDER_CONSTRUCTION", "ANNOUNCED", "PLANNED", "NOT_APPLICABLE", "UNKNOWN"] },
        "comparability": { "enum": ["COMPARABLE", "CONTEXT_ONLY", "NOT_COMPARABLE"] },
        "disputeGroupId": { "type": "string" }, "projectId": { "type": "string" }, "eventId": { "type": "string" },
        "evidence": { "type": "array", "items": { "$ref": "#/$defs/evidence" } }, "notes": { "type": "string" }
      },
      "allOf": [
        { "if": { "properties": { "valueState": { "const": "MISSING" } } }, "then": { "properties": { "claimStatus": { "const": "UNAVAILABLE" } }, "not": { "anyOf": [{ "required": ["valueNumeric"] }, { "required": ["valueText"] }, { "required": ["valueBoolean"] }] } } },
        { "if": { "properties": { "valueState": { "const": "SOURCED_ZERO" } } }, "then": { "required": ["valueNumeric"], "properties": { "valueNumeric": { "const": 0 } } } }
      ]
    },
    "project": { "type": "object", "required": ["id", "name", "ownerEntityId", "geographyIds", "claimStatus", "lifecycleStage", "confidence", "sourceIds"], "properties": { "id": { "$ref": "#/$defs/id" }, "name": { "type": "string" }, "ownerEntityId": { "type": "string" }, "geographyIds": { "type": "array", "items": { "type": "string" } }, "claimStatus": { "$ref": "#/$defs/claimStatus" }, "lifecycleStage": { "type": "string" }, "confidence": { "$ref": "#/$defs/confidence" }, "sourceIds": { "type": "array", "items": { "type": "string" } } } },
    "event": { "type": "object", "required": ["id", "type", "title", "eventDate", "geographyIds", "entityIds", "projectIds", "claimStatus", "confidence", "sourceIds"], "properties": { "id": { "$ref": "#/$defs/id" }, "type": { "type": "string" }, "title": { "type": "string" }, "eventDate": { "type": "string", "format": "date" }, "geographyIds": { "type": "array", "items": { "type": "string" } }, "entityIds": { "type": "array", "items": { "type": "string" } }, "projectIds": { "type": "array", "items": { "type": "string" } }, "claimStatus": { "$ref": "#/$defs/claimStatus" }, "confidence": { "$ref": "#/$defs/confidence" }, "sourceIds": { "type": "array", "items": { "type": "string" } } } },
    "review": { "type": "object", "required": ["id", "claim", "decision", "claimStatus", "reason", "sourceIds"], "properties": { "id": { "$ref": "#/$defs/id" }, "claim": { "type": "string" }, "decision": { "enum": ["ACCEPTED", "REJECTED", "CONTEXT_ONLY", "NEEDS_SOURCE"] }, "claimStatus": { "$ref": "#/$defs/claimStatus" }, "reason": { "type": "string" }, "sourceIds": { "type": "array", "items": { "type": "string" } } } }
  }
}
