{
  "openapi": "3.1.0",
  "info": {
    "title": "Free Design Tool Marketplace API",
    "description": "Marketplace catalog, checkout, order status, and health endpoints for Free Design Tool.",
    "version": "1.0.0"
  },
  "servers": [{ "url": "https://api.freedesigntool.com" }],
  "paths": {
    "/api/market/products": {
      "get": {
        "operationId": "listMarketplaceProducts",
        "summary": "List marketplace products",
        "responses": {
          "200": { "description": "Product list" },
          "500": { "$ref": "#/components/responses/InternalServerError" }
        }
      }
    },
    "/api/market/products/{id}": {
      "get": {
        "operationId": "getMarketplaceProduct",
        "summary": "Get a marketplace product",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": {
          "200": { "description": "Product" },
          "404": { "$ref": "#/components/responses/ProductNotFound" },
          "500": { "$ref": "#/components/responses/InternalServerError" }
        }
      }
    },
    "/api/market/categories": {
      "get": {
        "operationId": "listMarketplaceCategories",
        "summary": "List marketplace categories",
        "responses": {
          "200": { "description": "Category list" },
          "500": { "$ref": "#/components/responses/InternalServerError" }
        }
      }
    },
    "/api/market/checkout": {
      "post": {
        "operationId": "createMarketplaceCheckout",
        "summary": "Start marketplace checkout",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email", "items"],
                "properties": {
                  "email": { "type": "string", "format": "email" },
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": ["productId", "quantity"],
                      "properties": {
                        "productId": { "type": "string" },
                        "quantity": { "type": "integer", "minimum": 1, "maximum": 10 }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Checkout session" },
          "400": { "$ref": "#/components/responses/CheckoutRequestInvalid" },
          "500": { "$ref": "#/components/responses/InternalServerError" }
        }
      }
    },
    "/api/market/orders/{id}": {
      "get": {
        "operationId": "getMarketplaceOrder",
        "summary": "Get order status",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "Authorization", "in": "header", "required": true, "schema": { "type": "string", "example": "Bearer <accessToken>" } }
        ],
        "responses": {
          "200": { "description": "Order status" },
          "401": { "$ref": "#/components/responses/OrderTokenRequired" },
          "404": { "$ref": "#/components/responses/OrderNotFound" },
          "500": { "$ref": "#/components/responses/InternalServerError" }
        }
      }
    },
    "/health": {
      "get": {
        "operationId": "getApiHealth",
        "summary": "Check API health",
        "responses": { "200": { "description": "API health status" } }
      }
    }
  },
  "components": {
    "schemas": {
      "ApiError": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message", "resolution"],
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" },
              "resolution": { "type": "string" }
            }
          }
        }
      }
    },
    "responses": {
      "ProductNotFound": { "description": "Product not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApiError" } } } },
      "CheckoutRequestInvalid": { "description": "Checkout request invalid", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApiError" } } } },
      "OrderTokenRequired": { "description": "Order token required", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApiError" } } } },
      "OrderNotFound": { "description": "Order not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApiError" } } } },
      "InternalServerError": { "description": "Internal server error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApiError" } } } }
    }
  }
}
