{
 "openapi": "3.1.0",
 "info": {
  "title": "ML-NIGHTWORX Market Intel API",
  "version": "1.0.0",
  "summary": "Report catalogue (free) and per-report dashboard feeds (paid, USD 95 / 95 USDC per report).",
  "description": "Free: the catalogue with Executive Overviews and headline KPIs. Paid: one feed per report with the full report as Markdown, every table as structured JSON (numeric tables also as tidy series flagged actual/estimate/projection), sources and a 24-hour PDF link. Pay once per report with USDC on Arbitrum One or a Stripe payment link, then exchange the tx hash or Checkout Session id at POST /unlock for a Bearer token scoped to that report (valid 30 days). Pay-per-report only; no subscriptions.",
  "contact": {
   "name": "ML-NIGHTWORX",
   "email": "access@ml-nightworx.io",
   "url": "https://reports.ml-nightworx.io/agents/"
  }
 },
 "servers": [
  {
   "url": "https://reports.ml-nightworx.io/api/v1"
  }
 ],
 "externalDocs": {
  "description": "Agent guide",
  "url": "https://reports.ml-nightworx.io/agents/"
 },
 "tags": [
  {
   "name": "catalog",
   "description": "Free, public"
  },
  {
   "name": "feed",
   "description": "Paid, Bearer token"
  },
  {
   "name": "payment"
  }
 ],
 "paths": {
  "/reports": {
   "get": {
    "tags": [
     "catalog"
    ],
    "operationId": "listReports",
    "summary": "List reports (free)",
    "security": [],
    "parameters": [
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "available",
        "preorder"
       ]
      }
     },
     {
      "name": "tag",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "ai",
        "aerospace",
        "uav",
        "rov",
        "robotics",
        "infra",
        "policy"
       ]
      }
     },
     {
      "name": "q",
      "in": "query",
      "description": "Case-insensitive text search over title, abstract and overview",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Catalogue",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Catalog"
        }
       }
      }
     }
    }
   }
  },
  "/reports/{slug}": {
   "get": {
    "tags": [
     "catalog"
    ],
    "operationId": "getReport",
    "summary": "One report with its free Executive Overview",
    "security": [],
    "parameters": [
     {
      "name": "slug",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "malaysia-ai-digital-export-economy-2030",
        "malaysia-ai-digital-export-economy-briefing",
        "malaysia-ai-infrastructure-reckoning",
        "uav-robotics-market-intelligence-2027-2029",
        "enterprise-ai-spend-2026",
        "enterprise-llm-spend-vs-consumer-adoption-2026"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Report",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Report"
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/reports/{slug}/feed": {
   "get": {
    "tags": [
     "feed"
    ],
    "operationId": "getReportFeed",
    "summary": "Paid dashboard feed for one report",
    "security": [
     {
      "bearerAuth": []
     }
    ],
    "parameters": [
     {
      "name": "slug",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "malaysia-ai-digital-export-economy-2030",
        "malaysia-ai-digital-export-economy-briefing",
        "malaysia-ai-infrastructure-reckoning",
        "uav-robotics-market-intelligence-2027-2029",
        "enterprise-ai-spend-2026",
        "enterprise-llm-spend-vs-consumer-adoption-2026"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Feed",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Feed"
        }
       }
      }
     },
     "401": {
      "description": "Token missing scope, forged or expired (body also carries payment instructions)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PaymentRequired"
        }
       }
      }
     },
     "402": {
      "description": "Payment required: no token sent. Body explains how to pay and includes an x402-style accepts block.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PaymentRequired"
        }
       }
      }
     },
     "403": {
      "description": "Token is for a different report",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "Report is a pre-order; no feed yet",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/unlock": {
   "post": {
    "tags": [
     "payment"
    ],
    "operationId": "unlock",
    "summary": "Exchange a verified payment for a report-scoped Bearer token",
    "security": [],
    "description": "USDC: send 95 native USDC on Arbitrum One to the pay_to wallet, wait for confirmations, then post {report, tx, email?}. A tx is redeemed once, for one report; repeating the call with the same email returns the same access. Card: post {session_id} from the Stripe return URL. Rate limited (10/min, 60/hour per IP).",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "oneOf": [
         {
          "$ref": "#/components/schemas/UnlockUsdc"
         },
         {
          "$ref": "#/components/schemas/UnlockStripe"
         }
        ]
       },
       "examples": {
        "usdc": {
         "value": {
          "report": "malaysia-ai-digital-export-economy-2030",
          "tx": "0xabababababababababababababababababababababababababababababababab",
          "email": "agent@example.com"
         }
        },
        "stripe": {
         "value": {
          "session_id": "cs_live_a1B2c3"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Unlocked",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/UnlockResponse"
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "402": {
      "description": "Payment not verified on-chain (wrong amount, recipient, asset, or not enough confirmations)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "Already redeemed (or pre-order report)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "410": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "headers": {
       "Retry-After": {
        "schema": {
         "type": "integer"
        }
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "bearerAuth": {
    "type": "http",
    "scheme": "bearer",
    "description": "Token from POST /unlock, scoped to one report, valid 30 days."
   }
  },
  "schemas": {
   "Error": {
    "type": "object",
    "required": [
     "error",
     "message"
    ],
    "properties": {
     "error": {
      "type": "string"
     },
     "message": {
      "type": "string"
     }
    }
   },
   "Price": {
    "type": "object",
    "required": [
     "amount",
     "currency"
    ],
    "properties": {
     "amount": {
      "type": "number"
     },
     "currency": {
      "type": "string",
      "const": "USD"
     },
     "note": {
      "type": "string"
     }
    }
   },
   "Kpi": {
    "type": "object",
    "required": [
     "indicator",
     "value",
     "source"
    ],
    "properties": {
     "indicator": {
      "type": "string"
     },
     "value": {
      "type": "string"
     },
     "source": {
      "type": "string"
     }
    }
   },
   "Source": {
    "type": "object",
    "required": [
     "name"
    ],
    "properties": {
     "name": {
      "type": "string"
     },
     "url": {
      "type": [
       "string",
       "null"
      ]
     }
    }
   },
   "Report": {
    "type": "object",
    "required": [
     "id",
     "slug",
     "title",
     "type",
     "status",
     "published_at",
     "updated_at",
     "format",
     "tags",
     "price",
     "overview_markdown",
     "key_findings",
     "headline_kpis",
     "overview_url",
     "md_url"
    ],
    "properties": {
     "id": {
      "type": "string"
     },
     "slug": {
      "type": "string"
     },
     "title": {
      "type": "string"
     },
     "short_title": {
      "type": [
       "string",
       "null"
      ]
     },
     "type": {
      "type": "string",
      "enum": [
       "full",
       "briefing"
      ]
     },
     "type_label": {
      "type": [
       "string",
       "null"
      ]
     },
     "status": {
      "type": "string",
      "enum": [
       "available",
       "preorder"
      ]
     },
     "expected": {
      "type": [
       "string",
       "null"
      ]
     },
     "published_at": {
      "type": "string",
      "description": "ISO 8601 date (YYYY-MM-DD or YYYY-MM)"
     },
     "updated_at": {
      "type": "string",
      "format": "date"
     },
     "pages": {
      "type": [
       "integer",
       "null"
      ]
     },
     "pages_note": {
      "type": [
       "string",
       "null"
      ]
     },
     "format": {
      "type": "string",
      "const": "PDF"
     },
     "tags": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "price": {
      "$ref": "#/components/schemas/Price"
     },
     "abstract": {
      "type": "string"
     },
     "answer_block": {
      "type": "string"
     },
     "key_findings": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "headline_kpis": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Kpi"
      }
     },
     "overview_markdown": {
      "type": "string"
     },
     "methodology": {
      "type": "string"
     },
     "sources": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Source"
      }
     },
     "overview_url": {
      "type": "string",
      "format": "uri"
     },
     "md_url": {
      "type": "string",
      "format": "uri"
     },
     "feed_url": {
      "type": [
       "string",
       "null"
      ],
      "format": "uri"
     },
     "feed_contents": {
      "type": [
       "array",
       "null"
      ],
      "items": {
       "type": "string"
      }
     },
     "purchase": {
      "type": "object"
     }
    }
   },
   "Catalog": {
    "type": "object",
    "required": [
     "schema_version",
     "count",
     "reports"
    ],
    "properties": {
     "schema_version": {
      "type": "string"
     },
     "api_version": {
      "type": "string"
     },
     "generated": {
      "type": "string"
     },
     "publisher": {
      "type": "object"
     },
     "pricing_model": {
      "type": "string"
     },
     "payment_rails": {
      "type": "object"
     },
     "endpoints": {
      "type": "object"
     },
     "count": {
      "type": "integer"
     },
     "reports": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Report"
      }
     }
    }
   },
   "SeriesPoint": {
    "type": "object",
    "required": [
     "series",
     "metric",
     "value",
     "unit",
     "period",
     "basis",
     "source"
    ],
    "properties": {
     "series": {
      "type": "string"
     },
     "metric": {
      "type": "string"
     },
     "value": {
      "type": "number"
     },
     "unit": {
      "type": "string"
     },
     "period": {
      "type": "string"
     },
     "basis": {
      "type": "string",
      "enum": [
       "actual",
       "estimate",
       "projection",
       "derived",
       "actual+estimate"
      ],
      "description": "actual = official/reported; estimate/projection/derived = ML-NIGHTWORX calculation, not an official figure"
     },
     "source": {
      "type": "string"
     },
     "raw": {
      "type": "string",
      "description": "Cell text exactly as printed in the PDF"
     }
    }
   },
   "Dataset": {
    "type": "object",
    "required": [
     "id",
     "type",
     "columns",
     "rows",
     "pages"
    ],
    "properties": {
     "id": {
      "type": "string"
     },
     "title": {
      "type": [
       "string",
       "null"
      ]
     },
     "pages": {
      "type": "array",
      "items": {
       "type": "integer"
      }
     },
     "type": {
      "type": "string",
      "enum": [
       "numeric",
       "text"
      ]
     },
     "columns": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "rows": {
      "type": "array",
      "items": {
       "type": "object",
       "additionalProperties": {
        "type": "string"
       }
      }
     },
     "rows_raw": {
      "type": "array",
      "items": {
       "type": "array",
       "items": {
        "type": "string"
       }
      }
     },
     "notes": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "source_refs": {
      "type": "array",
      "items": {
       "type": "integer"
      }
     },
     "source_names": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "series": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/SeriesPoint"
      }
     },
     "series_note": {
      "type": "string"
     }
    }
   },
   "FeedSource": {
    "type": "object",
    "required": [
     "ref",
     "citation"
    ],
    "properties": {
     "ref": {
      "type": "integer"
     },
     "citation": {
      "type": "string"
     },
     "url": {
      "type": [
       "string",
       "null"
      ]
     }
    }
   },
   "Feed": {
    "type": "object",
    "required": [
     "report",
     "summary_markdown",
     "datasets",
     "sources",
     "pdf_url"
    ],
    "properties": {
     "report": {
      "type": "string"
     },
     "title": {
      "type": "string"
     },
     "published_at": {
      "type": "string"
     },
     "updated_at": {
      "type": "string"
     },
     "token_expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "pdf_url": {
      "type": "string",
      "format": "uri",
      "description": "Signed link, valid 24 hours"
     },
     "pdf_expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "summary_markdown": {
      "type": "string"
     },
     "datasets": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Dataset"
      }
     },
     "sources": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/FeedSource"
      }
     },
     "extraction": {
      "type": "object"
     }
    }
   },
   "UnlockUsdc": {
    "type": "object",
    "required": [
     "report",
     "tx"
    ],
    "additionalProperties": false,
    "properties": {
     "report": {
      "type": "string",
      "enum": [
       "malaysia-ai-digital-export-economy-2030",
       "malaysia-ai-digital-export-economy-briefing",
       "malaysia-ai-infrastructure-reckoning",
       "uav-robotics-market-intelligence-2027-2029",
       "enterprise-ai-spend-2026",
       "enterprise-llm-spend-vs-consumer-adoption-2026"
      ]
     },
     "tx": {
      "type": "string",
      "pattern": "^0x[0-9a-fA-F]{64}$"
     },
     "email": {
      "type": "string",
      "format": "email"
     }
    }
   },
   "UnlockStripe": {
    "type": "object",
    "required": [
     "session_id"
    ],
    "additionalProperties": false,
    "properties": {
     "session_id": {
      "type": "string",
      "pattern": "^cs_(live|test)_[A-Za-z0-9]+$"
     },
     "report": {
      "type": "string",
      "enum": [
       "malaysia-ai-digital-export-economy-2030",
       "malaysia-ai-digital-export-economy-briefing",
       "malaysia-ai-infrastructure-reckoning",
       "uav-robotics-market-intelligence-2027-2029",
       "enterprise-ai-spend-2026",
       "enterprise-llm-spend-vs-consumer-adoption-2026"
      ]
     }
    }
   },
   "UnlockResponse": {
    "type": "object",
    "required": [
     "ok",
     "report",
     "token",
     "token_type",
     "expires_at",
     "feed_url",
     "pdf_url"
    ],
    "properties": {
     "ok": {
      "type": "boolean"
     },
     "report": {
      "type": "string"
     },
     "token": {
      "type": "string"
     },
     "token_type": {
      "type": "string",
      "const": "Bearer"
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "reissued": {
      "type": "boolean"
     },
     "feed_url": {
      "type": "string",
      "format": "uri"
     },
     "pdf_url": {
      "type": "string",
      "format": "uri"
     },
     "pdf_expires_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "PaymentRequired": {
    "type": "object",
    "required": [
     "error",
     "message",
     "how_to_pay",
     "accepts"
    ],
    "properties": {
     "error": {
      "type": "string"
     },
     "message": {
      "type": "string"
     },
     "report": {
      "type": "string"
     },
     "price": {
      "$ref": "#/components/schemas/Price"
     },
     "how_to_pay": {
      "type": "object"
     },
     "x402Version": {
      "type": "integer"
     },
     "accepts": {
      "type": "array",
      "items": {
       "type": "object",
       "required": [
        "scheme",
        "network",
        "maxAmountRequired",
        "asset",
        "payTo",
        "resource"
       ],
       "properties": {
        "scheme": {
         "type": "string"
        },
        "network": {
         "type": "string"
        },
        "maxAmountRequired": {
         "type": "string"
        },
        "asset": {
         "type": "string"
        },
        "payTo": {
         "type": "string"
        },
        "resource": {
         "type": "string"
        },
        "description": {
         "type": "string"
        },
        "mimeType": {
         "type": "string"
        },
        "maxTimeoutSeconds": {
         "type": "integer"
        },
        "extra": {
         "type": "object"
        }
       }
      }
     }
    }
   }
  }
 }
}
