{
  "openapi": "3.1.0",
  "info": {
    "title": "FOBCalc Agent API",
    "version": "1.0.0",
    "description": "Read-only JSON API over public content on fobcalc.com. No authentication required."
  },
  "servers": [
    {
      "url": "https://fobcalc.com/agent-api"
    }
  ],
  "paths": {
    "/search": {
      "get": {
        "operationId": "searchSite",
        "summary": "Search pages by keyword",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 25,
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matching pages",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "query": {
                      "type": "string"
                    },
                    "count": {
                      "type": "integer"
                    },
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Page"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/pages": {
      "get": {
        "operationId": "listPages",
        "summary": "List public pages",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Page index",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": {
                      "type": "integer"
                    },
                    "offset": {
                      "type": "integer"
                    },
                    "pages": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Page"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/page": {
      "get": {
        "operationId": "getPage",
        "summary": "Read a page as Markdown",
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Page body",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string"
                    },
                    "markdown": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Page not found"
          }
        }
      }
    },
    "/health": {
      "get": {
        "operationId": "health",
        "summary": "Health check",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/calculate/{kind}": {
      "get": {
        "operationId": "calculate",
        "summary": "Run an export-pricing calculation (fobcalc.com only)",
        "description": "Same formulas as fobcalc.com/calc.js. Rates are fractions (0.2 = 20%). Money inputs must share one currency.",
        "parameters": [
          {
            "name": "kind",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "fob-cost",
                "export-price",
                "landed-cost",
                "import-charges",
                "margin"
              ]
            }
          },
          {
            "name": "exw_unit_cost",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0
            }
          },
          {
            "name": "cost_per_unit",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0
            }
          },
          {
            "name": "selling_price_per_unit",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0
            }
          },
          {
            "name": "inland_total",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0
            }
          },
          {
            "name": "port_total",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0
            }
          },
          {
            "name": "quantity",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "margin_rate",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0,
              "exclusiveMaximum": 1
            }
          },
          {
            "name": "insurance_rate",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0,
              "exclusiveMaximum": 1
            }
          },
          {
            "name": "cif_value",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0
            }
          },
          {
            "name": "duty_rate",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0,
              "exclusiveMaximum": 1
            }
          },
          {
            "name": "brokerage",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0
            }
          },
          {
            "name": "port_charges",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0
            }
          },
          {
            "name": "inland_delivery",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0
            }
          },
          {
            "name": "tax_rate",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0,
              "exclusiveMaximum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Calculation result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "404": {
            "description": "Calculation not available for this site"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Page": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "summary": {
            "type": "string"
          }
        }
      }
    }
  }
}