{
  "openapi": "3.1.0",
  "info": {
    "title": "Simbotica SIM Card API",
    "version": "1.0.0",
    "description": "KYC-free physical SIM card ordering via x402 USDC micropayments. Supports Base Mainnet and Ethereum Mainnet.",
    "contact": { "email": "orders@simbotica.xyz", "url": "https://simbotica.xyz" },
    "x-payment-protocol": "x402",
    "x-payment-docs": "/llms.txt"
  },
  "servers": [
    { "url": "https://simbotica.xyz", "description": "Production" }
  ],
  "paths": {
    "/api/submit-order-base": {
      "post": {
        "summary": "Order SIM card — Base Mainnet (USDC)",
        "description": "Place a KYC-free SIM card order. Protected by x402: send without X-PAYMENT to receive 402 + payment terms, then resend with signed X-PAYMENT header. Network: Base (eip155:8453). Price: $0.10 USDC per SIM.",
        "operationId": "submitOrderBase",
        "x-payment": {
          "protocol": "x402",
          "network": "base",
          "price": "$0.10",
          "asset": "USDC",
          "facilitator": "https://facilitator.xpay.sh"
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/OrderRequest" }
            }
          }
        },
        "parameters": [
          {
            "name": "X-PAYMENT",
            "in": "header",
            "description": "Base64-encoded x402 payment payload (required on second request after receiving 402)",
            "required": false,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Order confirmed",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/OrderSuccess" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "402": { "$ref": "#/components/responses/PaymentRequired" },
          "500": { "$ref": "#/components/responses/ServerError" }
        }
      }
    },
    "/api/submit-order-ethereum": {
      "post": {
        "summary": "Order SIM card — Ethereum Mainnet (USDC)",
        "description": "Place a KYC-free SIM card order. Protected by x402: send without X-PAYMENT to receive 402 + payment terms, then resend with signed X-PAYMENT header. Network: Ethereum Mainnet (eip155:1). Price: $0.10 USDC per SIM.",
        "operationId": "submitOrderEthereum",
        "x-payment": {
          "protocol": "x402",
          "network": "ethereum-mainnet",
          "price": "$0.10",
          "asset": "USDC",
          "facilitator": "https://facilitator.primev.xyz"
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/OrderRequest" }
            }
          }
        },
        "parameters": [
          {
            "name": "X-PAYMENT",
            "in": "header",
            "description": "Base64-encoded x402 payment payload (required on second request after receiving 402)",
            "required": false,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Order confirmed",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/OrderSuccess" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "402": { "$ref": "#/components/responses/PaymentRequired" },
          "500": { "$ref": "#/components/responses/ServerError" }
        }
      }
    },
    "/health": {
      "get": {
        "summary": "Health check",
        "operationId": "healthCheck",
        "responses": {
          "200": {
            "description": "Server is healthy",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "status": { "type": "string", "example": "ok" } } } } }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "OrderRequest": {
        "type": "object",
        "required": ["quantity", "email", "payment"],
        "properties": {
          "quantity": {
            "type": "integer",
            "minimum": 1,
            "maximum": 3,
            "description": "Number of SIM cards (1–3 per customer)",
            "example": 1
          },
          "email": {
            "type": "string",
            "format": "email",
            "description": "Email for order confirmation and shipping details",
            "example": "agent@example.com"
          },
          "payment": {
            "type": "string",
            "enum": ["usdc_x402"],
            "description": "Payment method — always usdc_x402 for this endpoint",
            "example": "usdc_x402"
          }
        }
      },
      "OrderSuccess": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": true },
          "orderRef": { "type": "string", "example": "SIM-1716825600000" },
          "txHash": { "type": "string", "nullable": true, "example": "0xabc123..." }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": { "type": "string" }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid request body",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } }
      },
      "PaymentRequired": {
        "description": "x402 payment required. Response body contains payment terms (accepts array with network, payTo, maxAmountRequired, asset, extra).",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "accepts": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "scheme":             { "type": "string", "example": "exact" },
                      "network":            { "type": "string", "example": "base" },
                      "payTo":              { "type": "string", "example": "0x..." },
                      "maxAmountRequired":  { "type": "string", "example": "100000" },
                      "asset":              { "type": "string", "example": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" },
                      "extra": {
                        "type": "object",
                        "properties": {
                          "name":    { "type": "string", "example": "USD Coin" },
                          "version": { "type": "string", "example": "2" }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "ServerError": {
        "description": "Server error",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } }
      }
    }
  }
}
