{
  "openapi": "3.1.0",
  "info": {
    "title": "GiftBack Secret Santa & Gift Ideas API",
    "version": "1.0.0",
    "description": "Free, no-account Secret Santa draw generator, prefilled gift exchange setup, and curated in-budget gift finder powered by GiftBack (https://joingiftback.com). The organizer sends one reveal link to each person. Anyone holding a link can open that match."
  },
  "servers": [
    {
      "url": "https://joingiftback.com",
      "description": "GiftBack Production"
    }
  ],
  "paths": {
    "/api/chatgpt/quick-exchange": {
      "post": {
        "operationId": "createQuickSecretSanta",
        "summary": "Create a live Secret Santa draw or prefilled GiftBack exchange link",
        "description": "When participants (2 to 50 unique names) are provided, runs a cryptographically random Secret Santa draw honoring optional keep-apart exclusions and returns one private GiftBack reveal URL per giver (never exposing matches in plaintext). When participants are omitted, returns a prefilled GiftBack exchange setup link with budget and theme so the organizer can invite everyone with wishlists from any store.",
        "x-openai-isConsequential": false,
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuickExchangeRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Secret Santa reveal links and/or prefilled GiftBack exchange link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuickExchangeResponse"
                }
              }
            }
          },
          "400": {
            "description": "Validation error or impossible exclusion constraints",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/chatgpt/gift-ideas": {
      "get": {
        "operationId": "findGiftIdeas",
        "summary": "Suggest in-budget gift ideas from GiftBack's curated catalog",
        "description": "Search GiftBack's curated catalog of quality brands and small makers (plus optional live store search) filtered by recipient, interest, category, age group, dislikes, and maximum budget.",
        "x-openai-isConsequential": false,
        "parameters": [
          {
            "name": "query",
            "in": "query",
            "required": false,
            "description": "Free-text search such as 'coffee lover', 'coworker under 25', 'cozy blanket', or 'dad who hikes'.",
            "schema": {
              "type": "string",
              "maxLength": 120
            }
          },
          {
            "name": "maxPrice",
            "in": "query",
            "required": false,
            "description": "Maximum gift price in USD (1 to 10000).",
            "schema": {
              "type": "number",
              "minimum": 1,
              "maximum": 10000
            }
          },
          {
            "name": "category",
            "in": "query",
            "required": false,
            "description": "Optional catalog category filter.",
            "schema": {
              "type": "string",
              "enum": [
                "cozy",
                "coffee",
                "kitchen",
                "tech",
                "books",
                "games",
                "beauty",
                "outdoors",
                "kids",
                "pets",
                "treats",
                "makers"
              ]
            }
          },
          {
            "name": "age",
            "in": "query",
            "required": false,
            "description": "Recipient age group.",
            "schema": {
              "type": "string",
              "enum": [
                "kids-0-4",
                "kids-5-8",
                "kids-9-12",
                "teens",
                "adults"
              ]
            }
          },
          {
            "name": "avoid",
            "in": "query",
            "required": false,
            "description": "Comma- or space-separated dislikes or allergens to exclude (e.g., 'candles nuts').",
            "schema": {
              "type": "string",
              "maxLength": 120
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Maximum number of gift ideas to return (1 to 12, default 6).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 12,
              "default": 6
            }
          },
          {
            "name": "includeLive",
            "in": "query",
            "required": false,
            "description": "Set true to supplement curated picks with live US store results.",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of in-budget gift ideas with store links",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GiftIdeasResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid query parameter",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "QuickExchangeRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 2,
            "maxLength": 60,
            "description": "Exchange title, e.g. 'Marketing Team Secret Santa' or 'Cozy Night In Swap'."
          },
          "budget": {
            "type": "number",
            "minimum": 1,
            "maximum": 10000,
            "description": "Target gift budget in USD, e.g. 25."
          },
          "theme": {
            "type": "string",
            "description": "Optional theme ID or name: secret-santa, book-exchange, coffee-tea, snack-swap, handmade, ornament-swap, recipe-swap, hometown, vinyl, hot-sauce, plants, or letters."
          },
          "participants": {
            "type": "array",
            "maxItems": 50,
            "description": "Optional list of 2 to 50 unique participant names to immediately draw private reveal links. Omit to return a prefilled setup link instead.",
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 40
            }
          },
          "exclusions": {
            "type": "array",
            "maxItems": 50,
            "description": "Optional pairs of participant names who must not draw each other (e.g. couples or housemates).",
            "items": {
              "type": "array",
              "minItems": 2,
              "maxItems": 2,
              "items": {
                "type": "string"
              }
            }
          },
          "language": {
            "type": "string",
            "enum": ["en", "es", "fr", "de", "pt", "it"],
            "default": "en",
            "description": "Language for reveal links."
          }
        }
      },
      "RevealLink": {
        "type": "object",
        "required": ["giver", "revealUrl"],
        "properties": {
          "giver": {
            "type": "string",
            "description": "Participant who should receive this private link."
          },
          "revealUrl": {
            "type": "string",
            "format": "uri",
            "description": "Private GiftBack reveal URL containing the encoded match in the URL fragment."
          }
        }
      },
      "ThemeSummary": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "description": "GiftBack theme identifier." },
          "name": { "type": "string", "description": "Display name of the theme." },
          "line": { "type": "string", "description": "Short tagline for the theme." },
          "ideas": {
            "type": "array",
            "description": "Concrete gift prompts for this theme.",
            "items": { "type": "string" }
          }
        }
      },
      "QuickExchangeResponse": {
        "type": "object",
        "required": [
          "ok",
          "mode",
          "exchangeName",
          "language",
          "participantCount",
          "createFullExchangeUrl",
          "quickGeneratorUrl",
          "whiteElephantUrl",
          "giftIdeasUrl",
          "shareMessage",
          "instructions"
        ],
        "properties": {
          "ok": { "type": "boolean", "description": "Always true on success." },
          "mode": {
            "type": "string",
            "enum": ["draw", "setup"],
            "description": "'draw' when private reveal links were generated; 'setup' when returning a prefilled full-exchange link."
          },
          "exchangeName": { "type": "string", "description": "Normalized exchange title." },
          "budget": { "type": ["number", "null"], "description": "Target gift budget in USD, or null." },
          "language": { "type": "string", "description": "Language code used for reveal links." },
          "theme": {
            "anyOf": [
              { "$ref": "#/components/schemas/ThemeSummary" },
              { "type": "null" }
            ],
            "description": "Matched GiftBack theme details, if applicable."
          },
          "participantCount": { "type": "integer", "description": "Number of drawn participants (0 in setup mode)." },
          "revealLinks": {
            "type": "array",
            "description": "Private per-giver reveal links (present when mode is 'draw').",
            "items": { "$ref": "#/components/schemas/RevealLink" }
          },
          "createFullExchangeUrl": {
            "type": "string",
            "format": "uri",
            "description": "Prefilled GiftBack link to create a full exchange with wishlists from any store and Santa-only addresses."
          },
          "quickGeneratorUrl": {
            "type": "string",
            "format": "uri",
            "description": "GiftBack browser Secret Santa name generator link."
          },
          "whiteElephantUrl": {
            "type": "string",
            "format": "uri",
            "description": "GiftBack online White Elephant game link."
          },
          "giftIdeasUrl": {
            "type": "string",
            "format": "uri",
            "description": "Matching GiftBack curated gift ideas page for the budget."
          },
          "shareMessage": {
            "type": "string",
            "description": "Ready-to-paste announcement message for the organizer."
          },
          "instructions": {
            "type": "string",
            "description": "Guidance for ChatGPT to relay to the user."
          }
        }
      },
      "GiftIdea": {
        "type": "object",
        "required": ["title", "price", "softPrice", "store", "why", "category", "buyUrl", "imageUrl", "source"],
        "properties": {
          "title": { "type": "string", "description": "Product name." },
          "price": { "type": "number", "description": "Approximate price in USD." },
          "softPrice": { "type": "string", "description": "Friendly rounded price label such as 'about $25'." },
          "store": { "type": "string", "description": "Brand or retailer name." },
          "why": { "type": "string", "description": "Short reason this makes a great gift." },
          "category": { "type": "string", "description": "Gift category." },
          "buyUrl": { "type": "string", "format": "uri", "description": "Direct link to buy the gift." },
          "imageUrl": { "type": "string", "format": "uri", "description": "Product photo URL." },
          "source": { "type": "string", "enum": ["curated", "live"], "description": "Whether the item came from GiftBack's curated catalog or live search." }
        }
      },
      "GiftIdeasResponse": {
        "type": "object",
        "required": ["ok", "query", "count", "ideas", "giftbackFinderUrl", "createExchangeUrl"],
        "properties": {
          "ok": { "type": "boolean", "description": "Always true on success." },
          "query": { "type": "string", "description": "Normalized search query." },
          "maxPrice": { "type": ["number", "null"], "description": "Maximum price filter in USD, if set." },
          "count": { "type": "integer", "description": "Number of gift ideas returned." },
          "ideas": {
            "type": "array",
            "description": "Matching in-budget gift ideas.",
            "items": { "$ref": "#/components/schemas/GiftIdea" }
          },
          "giftbackFinderUrl": {
            "type": "string",
            "format": "uri",
            "description": "Best matching GiftBack editorial gift finder page."
          },
          "createExchangeUrl": {
            "type": "string",
            "format": "uri",
            "description": "Prefilled GiftBack link to start a Secret Santa exchange with this budget."
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["ok", "error"],
        "properties": {
          "ok": { "type": "boolean", "description": "Always false on error." },
          "error": { "type": "string", "description": "Human-readable error explanation." }
        }
      }
    }
  }
}
