{
  "openapi": "3.0.0",
  "info": {
    "title": "Gift Under 200 API",
    "description": "Public API for discovering curated gift ideas under $200. This API provides access to a database of products with prices, descriptions, images, and affiliate links.",
    "version": "1.0.0",
    "contact": {
      "email": "contact@giftunder200.com"
    }
  },
  "servers": [
    {
      "url": "https://giftunder200.com",
      "description": "Production server"
    }
  ],
  "paths": {
    "/api/products": {
      "get": {
        "summary": "Get products",
        "description": "Retrieve a list of products with optional filtering by price segment, gender, tags, and search terms.",
        "operationId": "getProducts",
        "parameters": [
          {
            "name": "segment",
            "in": "query",
            "description": "Price segment filter",
            "required": false,
            "schema": {
              "type": "string",
              "enum": ["under50", "under200"]
            }
          },
          {
            "name": "gender",
            "in": "query",
            "description": "Gender target filter",
            "required": false,
            "schema": {
              "type": "string",
              "enum": ["men", "women"]
            }
          },
          {
            "name": "tag",
            "in": "query",
            "description": "Filter by tag slug",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "description": "Search in product title and description",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of products to return (default: 50, max: 100)",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100,
              "minimum": 1
            }
          },
          {
            "name": "offset",
            "in": "query",
            "description": "Number of products to skip for pagination",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 0,
              "minimum": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProductsResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Product": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Unique product identifier"
          },
          "slug": {
            "type": "string",
            "description": "URL-friendly product identifier"
          },
          "title": {
            "type": "string",
            "description": "Product title"
          },
          "description": {
            "type": "string",
            "description": "Product description"
          },
          "price": {
            "type": "number",
            "format": "float",
            "description": "Product price in USD"
          },
          "price_segment": {
            "type": "string",
            "enum": ["under50", "under200"],
            "description": "Price segment category"
          },
          "external_link": {
            "type": "string",
            "format": "uri",
            "description": "Affiliate link to purchase the product"
          },
          "image_url": {
            "type": "string",
            "format": "uri",
            "description": "Product image URL"
          },
          "why_text": {
            "type": "string",
            "nullable": true,
            "description": "Explanation of why this product is recommended"
          },
          "gender_target": {
            "type": "string",
            "enum": ["men", "women", "unisex"],
            "nullable": true,
            "description": "Target gender for this product"
          },
          "country_of_provenance": {
            "type": "string",
            "nullable": true,
            "description": "ISO 3166-1 alpha-2 country code"
          },
          "tags": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Tag"
            },
            "description": "Product tags"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Full URL to the product page on giftunder200.com"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "Product creation timestamp"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "Product last update timestamp"
          }
        },
        "required": ["id", "slug", "title", "description", "price", "price_segment", "external_link", "image_url", "url"]
      },
      "Tag": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          }
        },
        "required": ["id", "name", "slug"]
      },
      "ProductsResponse": {
        "type": "object",
        "properties": {
          "products": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Product"
            }
          },
          "pagination": {
            "$ref": "#/components/schemas/Pagination"
          },
          "filters": {
            "$ref": "#/components/schemas/Filters"
          }
        },
        "required": ["products", "pagination", "filters"]
      },
      "Pagination": {
        "type": "object",
        "properties": {
          "total": {
            "type": "integer",
            "description": "Total number of products matching the filters"
          },
          "limit": {
            "type": "integer",
            "description": "Maximum number of products returned"
          },
          "offset": {
            "type": "integer",
            "description": "Number of products skipped"
          },
          "has_more": {
            "type": "boolean",
            "description": "Whether there are more products available"
          }
        },
        "required": ["total", "limit", "offset", "has_more"]
      },
      "Filters": {
        "type": "object",
        "properties": {
          "segment": {
            "type": "string",
            "nullable": true,
            "enum": ["under50", "under200"]
          },
          "gender": {
            "type": "string",
            "nullable": true,
            "enum": ["men", "women"]
          },
          "tag": {
            "type": "string",
            "nullable": true
          },
          "search": {
            "type": "string",
            "nullable": true
          }
        }
      }
    }
  }
}

