{
  "openapi": "3.1.0",
  "info": {
    "title": "x402 In-Game Shop API",
    "description": "XMTP-powered in-game shop with x402 payments on Base",
    "version": "1.0.0",
    "contact": {
      "name": "OWB Studio",
      "url": "https://x402-shop.pages.dev"
    }
  },
  "servers": [
    {
      "url": "https://x402-shop-api.fawesome-hypercasual.workers.dev",
      "description": "Production API"
    }
  ],
  "tags": [
    {
      "name": "Shop",
      "description": "Shop operations"
    },
    {
      "name": "Purchase",
      "description": "Purchase and payment operations"
    }
  ],
  "paths": {
    "/api/shop/items": {
      "get": {
        "operationId": "listItems",
        "summary": "List all shop items",
        "tags": ["Shop"],
        "responses": {
          "200": {
            "description": "List of available items",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ShopItem"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/shop/purchase": {
      "post": {
        "operationId": "purchaseItem",
        "summary": "Purchase an item (returns 402 Payment Required)",
        "tags": ["Purchase"],
        "x-payment-info": {
          "pricingMode": "fixed",
          "currency": "USDC",
          "network": "base",
          "protocols": ["x402"]
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "itemId": {
                    "type": "string",
                    "description": "Item identifier"
                  },
                  "userId": {
                    "type": "string",
                    "description": "Buyer's wallet address"
                  }
                },
                "required": ["itemId", "userId"]
              }
            }
          }
        },
        "responses": {
          "402": {
            "description": "Payment Required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentRequired"
                }
              }
            }
          }
        }
      }
    },
    "/api/shop/verify": {
      "post": {
        "operationId": "verifyPurchase",
        "summary": "Verify payment and deliver item",
        "tags": ["Purchase"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "itemId": {
                    "type": "string"
                  },
                  "userId": {
                    "type": "string"
                  },
                  "txHash": {
                    "type": "string",
                    "description": "Transaction hash on Base"
                  }
                },
                "required": ["itemId", "userId", "txHash"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Purchase verified and item delivered",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PurchaseResult"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ShopItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "price": {
            "type": "string",
            "description": "Price in USDC (6 decimals)"
          },
          "currency": {
            "type": "string",
            "enum": ["USDC"]
          }
        }
      },
      "PaymentRequired": {
        "type": "object",
        "properties": {
          "amount": {
            "type": "string",
            "description": "Amount in smallest units (6 decimals for USDC)"
          },
          "currency": {
            "type": "string"
          },
          "recipient": {
            "type": "string",
            "description": "Payment recipient address"
          },
          "metadata": {
            "type": "object",
            "properties": {
              "itemId": { "type": "string" },
              "userId": { "type": "string" },
              "orderId": { "type": "string" }
            }
          }
        }
      },
      "PurchaseResult": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "orderId": {
            "type": "string"
          },
          "item": {
            "$ref": "#/components/schemas/ShopItem"
          },
          "txHash": {
            "type": "string"
          }
        }
      }
    }
  }
}
