{
  "openapi": "3.1.0",
  "info": {
    "title": "Epic Snackbox Autonomous Agent Commerce API",
    "description": "API allowing AI agents, LLMs, and autonomous bots to browse curated snack box offerings, request programmatic quotes with shipping calculation, and settle physical product deliveries directly on-chain using USDC stablecoins on Base or Solana.",
    "version": "1.0.0",
    "contact": {
      "name": "Epic Snackbox Agent Support",
      "url": "https://epicsnackbox.com",
      "email": "support@epicsnackbox.com"
    }
  },
  "servers": [
    {
      "url": "https://epicsnackbox.com",
      "description": "Production Server"
    }
  ],
  "paths": {
    "/api/agent/catalog": {
      "get": {
        "operationId": "getSnackCatalog",
        "summary": "Get Snack Box Catalog & Supported Settlement Networks",
        "description": "Returns available box tiers (Standard $35.77, Mega $59.77, Ultimate $99.77), item counts, descriptions, and the active USDC receiving addresses for Base and Solana.",
        "responses": {
          "200": {
            "description": "Successful catalog response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CatalogResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/agent/quote": {
      "post": {
        "operationId": "getBoxQuote",
        "summary": "Generate Executable Price Quote with Payment Instructions",
        "description": "Calculates the deterministic pricing and free shipping eligibility for the destination state, returning exact USDC amounts and receiving addresses for Base and Solana.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuoteRequest"
              },
              "example": {
                "tier": "standard",
                "shipping_state": "NY"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Executable price quote",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuoteResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid quote request parameters"
          }
        }
      }
    },
    "/api/agent/checkout": {
      "post": {
        "operationId": "submitOrderPayment",
        "summary": "Submit On-Chain Stablecoin Payment & Trigger Shipment",
        "description": "Verifies the on-chain USDC transfer transaction on Base or Solana, prevents replay attacks, records the order in the database, and dispatches the package to the physical shipping address.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckoutRequest"
              },
              "example": {
                "chain": "base",
                "tx_hash": "0x4e6e6900f6828a2a78f30bb0ef4d5f29911e2f7b8d4f07a726359fca7f7ff938",
                "tier": "standard",
                "customer": {
                  "name": "Jane Doe",
                  "email": "jane@example.com"
                },
                "shipping": {
                  "name": "Jane Doe",
                  "street": "123 Main St Apt 4B",
                  "city": "New York",
                  "state": "NY",
                  "zipcode": "10001",
                  "country": "US"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payment successfully verified and order queued for delivery",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutResponse"
                }
              }
            }
          },
          "400": {
            "description": "Verification failed (underpaid, wrong recipient, or unconfirmed transaction)"
          },
          "409": {
            "description": "Replay attack detected: transaction has already been used for another order"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CatalogResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "store": {
            "type": "object",
            "properties": {
              "name": { "type": "string" },
              "url": { "type": "string" },
              "currency": { "type": "string" },
              "settlement_tokens": {
                "type": "array",
                "items": { "type": "string" }
              },
              "free_shipping": { "type": "string" }
            }
          },
          "tiers": { "type": "object" },
          "supported_chains": { "type": "object" }
        }
      },
      "QuoteRequest": {
        "type": "object",
        "properties": {
          "tier": {
            "type": "string",
            "enum": ["standard", "mega", "ultimate"],
            "default": "standard",
            "description": "Selected box tier"
          },
          "shipping_state": {
            "type": "string",
            "example": "NY",
            "description": "Two-letter US state code"
          }
        }
      },
      "QuoteResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "quote_id": { "type": "string" },
          "tier": { "type": "string" },
          "summary": {
            "type": "object",
            "properties": {
              "subtotal": { "type": "number" },
              "shipping": { "type": "number" },
              "discount": { "type": "number" },
              "total_usd": { "type": "number" }
            }
          },
          "payment_instructions": { "type": "object" },
          "next_step": { "type": "string" }
        }
      },
      "CheckoutRequest": {
        "type": "object",
        "required": ["chain", "tx_hash", "shipping"],
        "properties": {
          "chain": {
            "type": "string",
            "enum": ["base", "solana"],
            "description": "Blockchain where payment was sent"
          },
          "tx_hash": {
            "type": "string",
            "description": "Transaction hash on Base (0x...) or signature on Solana"
          },
          "tier": {
            "type": "string",
            "enum": ["standard", "mega", "ultimate"],
            "default": "standard"
          },
          "customer": {
            "type": "object",
            "properties": {
              "name": { "type": "string" },
              "email": { "type": "string", "format": "email" }
            }
          },
          "shipping": {
            "type": "object",
            "required": ["name", "street", "city", "state", "zipcode"],
            "properties": {
              "name": { "type": "string" },
              "street": { "type": "string" },
              "city": { "type": "string" },
              "state": { "type": "string" },
              "zipcode": { "type": "string" },
              "country": { "type": "string", "default": "US" }
            }
          }
        }
      },
      "CheckoutResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "order_id": { "type": "string" },
          "status": { "type": "string", "example": "paid" },
          "chain": { "type": "string" },
          "payment_ref": { "type": "string" },
          "amount_paid_usdc": { "type": "number" },
          "payer": { "type": "string" },
          "shipping_to": { "type": "object" },
          "message": { "type": "string" }
        }
      }
    }
  }
}
