{
  "openapi": "3.1.0",
  "info": {
    "title": "CYBERSHOP AI Public API",
    "summary": "B2B IT-инфраструктура: каталог, AI-конфигуратор, лиды, авторизация.",
    "description": "Public surface CYBERSHOP AI. Read-only каталог обслуживается через Firebase Hosting (статические JSON), а доменные действия (лиды, авторизация) — через Firebase Cloud Functions, проксированные на /api/hub/**.",
    "version": "2026.04.19",
    "contact": {
      "name": "ТОО Smart System (CYBERSHOP AI)",
      "email": "info@cybershop.kz",
      "url": "https://ai.cybershop.kz/"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://cybershop.kz/oferta"
    }
  },
  "servers": [
    { "url": "https://ai.cybershop.kz", "description": "Production" }
  ],
  "tags": [
    { "name": "catalog", "description": "Каталог APICore live snapshot (~1660 SKU)" },
    { "name": "mcp", "description": "Model Context Protocol endpoint at /mcp" },
    { "name": "leads", "description": "Заявки на проекты и обратная связь" },
    { "name": "auth", "description": "Аутентификация и аналитика входов/регистраций" }
  ],
  "paths": {
    "/data/catalog/index.json": {
      "get": {
        "tags": ["catalog"],
        "summary": "Получить статический индекс каталога",
        "operationId": "getCatalogIndex",
        "responses": {
          "200": {
            "description": "Каталог в формате JSON",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/CatalogIndex" }
              }
            }
          }
        }
      }
    },
    "/api/hub/submitLead": {
      "post": {
        "tags": ["leads"],
        "summary": "Создать заявку на проект",
        "operationId": "submitLead",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/LeadInput" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Заявка принята",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/LeadAccepted" }
              }
            }
          },
          "400": { "description": "Невалидное тело запроса" }
        }
      }
    },
    "/api/hub/submitAuthEvent": {
      "post": {
        "tags": ["auth"],
        "summary": "Зарегистрировать событие аутентификации (fire-and-forget)",
        "operationId": "submitAuthEvent",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/AuthEvent" }
            }
          }
        },
        "responses": {
          "200": { "description": "Событие принято" },
          "400": { "description": "Невалидное событие" }
        }
      }
    },
    "/api/hub/adminLeads": {
      "get": {
        "tags": ["leads"],
        "summary": "Получить список заявок (только для администраторов)",
        "operationId": "adminLeads",
        "security": [{ "AdminKey": [] }],
        "responses": {
          "200": {
            "description": "Массив заявок",
            "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/LeadStored" } } } }
          },
          "401": { "description": "Не авторизован" }
        }
      }
    },
    "/mcp": {
      "get": {
        "tags": ["mcp"],
        "summary": "MCP discovery (server info and tool names)",
        "operationId": "mcpDiscovery",
        "responses": {
          "200": { "description": "MCP server descriptor" }
        }
      },
      "post": {
        "tags": ["mcp"],
        "summary": "MCP JSON-RPC (tools/list, tools/call)",
        "operationId": "mcpJsonRpc",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "jsonrpc": { "type": "string" },
                  "id": {},
                  "method": { "type": "string", "enum": ["initialize", "tools/list", "tools/call"] },
                  "params": { "type": "object" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "JSON-RPC result" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "AdminKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Hub-Admin-Key",
        "description": "Секретный ключ администратора для доступа к лидам"
      }
    },
    "schemas": {
      "CatalogIndex": {
        "type": "object",
        "properties": {
          "updatedAt": { "type": "string", "format": "date-time" },
          "items": { "type": "array", "items": { "$ref": "#/components/schemas/CatalogItem" } }
        }
      },
      "CatalogItem": {
        "type": "object",
        "required": ["id", "name", "price"],
        "properties": {
          "id": { "type": "string" },
          "pn": { "type": "string", "description": "Партномер / SKU" },
          "name": { "type": "string" },
          "brand": { "type": "string" },
          "category": { "type": "string" },
          "price": { "type": "number", "minimum": 0, "description": "Цена в KZT" },
          "stock": {
            "oneOf": [
              { "type": "integer", "minimum": 0 },
              { "type": "string", "enum": ["order"] }
            ]
          },
          "is_poe_consumer": { "type": "boolean" },
          "power_draw_w": { "type": "number" },
          "switch_total_poe_budget_w": { "type": "number" },
          "switch_poe_port_count": { "type": "integer" },
          "productUrl": { "type": "string", "format": "uri" }
        }
      },
      "LeadInput": {
        "type": "object",
        "required": ["invoiceNo", "title"],
        "properties": {
          "type": { "type": "string", "enum": ["project_lead", "contact_lead", "demo_request"], "default": "project_lead" },
          "invoiceNo": { "type": "string", "maxLength": 64 },
          "title": { "type": "string", "maxLength": 500 },
          "brief": { "type": "string", "maxLength": 8000 },
          "theme": { "type": "string", "maxLength": 32 },
          "contactEmail": { "type": "string", "format": "email" },
          "contactPhone": { "type": "string" },
          "contactName": { "type": "string" },
          "analysis": { "type": "object" },
          "clientMeta": { "type": "object" }
        }
      },
      "LeadAccepted": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "id": { "type": "string" },
          "createdAt": { "type": "string", "format": "date-time" }
        }
      },
      "LeadStored": {
        "allOf": [
          { "$ref": "#/components/schemas/LeadInput" },
          {
            "type": "object",
            "properties": {
              "id": { "type": "string" },
              "createdAt": { "type": "string", "format": "date-time" },
              "status": { "type": "string", "enum": ["new", "in_progress", "won", "lost"] }
            }
          }
        ]
      },
      "AuthEvent": {
        "type": "object",
        "required": ["event"],
        "properties": {
          "event": { "type": "string", "enum": ["signup", "signin", "signin_social", "phone_otp", "reset_request", "logout"] },
          "uid": { "type": "string" },
          "email": { "type": "string", "format": "email" },
          "phone": { "type": "string" },
          "name": { "type": "string" },
          "provider": { "type": "string", "enum": ["password", "google", "github", "apple", "phone"] },
          "ts": { "type": "string", "format": "date-time" },
          "userAgent": { "type": "string" },
          "locale": { "type": "string" }
        }
      }
    }
  }
}
