{
  "openapi": "3.1.0",
  "info": {
    "title": "Thabit Labs MENA Climate & Carbon Data API",
    "version": "1.0.0",
    "description": "Edge REST API serving audited Egypt and MENA EU CBAM CN-code defaults, reconciled EEHC/IFI/Ember electricity grid emission factors, and primary EgyptERA electricity regulations.",
    "contact": {
      "name": "Thabit Labs LLC",
      "email": "contact@thabitlabs.com",
      "url": "https://thabitlabs.com"
    }
  },
  "servers": [
    {
      "url": "https://thabitlabs.com",
      "description": "Production Cloudflare Edge"
    }
  ],
  "components": {
    "securitySchemes": {
      "ProApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Optional Pro Licence key raising pagination cap from 25 (Open Core) to 500 records per request."
      }
    }
  },
  "paths": {
    "/api/v1/health": {
      "get": {
        "summary": "API health & SHA-256 dataset provenance manifest",
        "responses": { "200": { "description": "Active service status and dataset manifest" } }
      }
    },
    "/api/v1/cbam": {
      "get": {
        "summary": "Search 260 EU CBAM CN/TARIC codes with Egypt-specific defaults and live liability calculation",
        "parameters": [
          { "name": "q", "in": "query", "schema": { "type": "string" }, "description": "Search CN code, digits, or product description" },
          { "name": "sector", "in": "query", "schema": { "type": "string" }, "description": "Filter by sector (Steel, Aluminium, Cement, Fertilisers)" },
          { "name": "egypt_only", "in": "query", "schema": { "type": "boolean" }, "description": "Filter to the 61 Egypt-specific default entries" },
          { "name": "year", "in": "query", "schema": { "type": "integer", "default": 2026 }, "description": "Compliance year (2026-2034) applying official default mark-ups" },
          { "name": "tonnes", "in": "query", "schema": { "type": "number" }, "description": "Optional export volume in tonnes for live EUR cost calculation" },
          { "name": "ets_eur", "in": "query", "schema": { "type": "number", "default": 75 }, "description": "EU ETS price in EUR/tCO2e" },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 25 } }
        ],
        "responses": { "200": { "description": "Matching CN codes with mark-ups and optional EUR estimate" } }
      }
    },
    "/api/v1/grid-factor": {
      "get": {
        "summary": "Query 17 reconciled Egypt electricity grid emission factor series (EEHC, UNFCCC IFI, Ember)",
        "parameters": [
          { "name": "series_id", "in": "query", "schema": { "type": "string" } },
          { "name": "source", "in": "query", "schema": { "type": "string" } },
          { "name": "period", "in": "query", "schema": { "type": "string" } },
          { "name": "boundary", "in": "query", "schema": { "type": "string", "enum": ["generation", "lifecycle"] } }
        ],
        "responses": { "200": { "description": "Reconciled emission factor series with exact boundary metadata" } }
      }
    },
    "/api/v1/regulations": {
      "get": {
        "summary": "Bilingual Arabic/English search across 149 primary EgyptERA electricity regulation PDFs",
        "parameters": [
          { "name": "q", "in": "query", "schema": { "type": "string" }, "description": "Arabic or English keyword" },
          { "name": "year", "in": "query", "schema": { "type": "string" } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 25 } }
        ],
        "responses": { "200": { "description": "Matching EgyptERA regulatory documents with official source URLs" } }
      }
    }
  }
}
