{
  "openapi": "3.0.3",
  "info": { "title": "BelezaLink API", "version": "1.0.0", "description": "API REST para gestão de salões, reservas, clientes, comandas, caixa, financeiro e integrações." },
  "servers": [{ "url": "https://app.belezalink.online/api" }],
  "tags": [{ "name": "Auth" }, { "name": "Salon" }, { "name": "Public" }, { "name": "Admin" }, { "name": "MCP" }],
  "paths": {
    "/health": { "get": { "summary": "Healthcheck", "responses": { "200": { "description": "Serviço disponível" } } } },
    "/auth/login": { "post": { "tags": ["Auth"], "summary": "Inicia sessão", "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/LoginRequest" } } } }, "responses": { "200": { "description": "Cookie HttpOnly criado" }, "400": { "$ref": "#/components/responses/BadRequest" }, "401": { "$ref": "#/components/responses/Unauthorized" } } } },
    "/auth/logout": { "post": { "tags": ["Auth"], "summary": "Revoga sessão", "security": [{ "cookieSession": [] }], "responses": { "200": { "description": "Sessão revogada" }, "401": { "$ref": "#/components/responses/Unauthorized" } } } },
    "/auth/me": { "get": { "tags": ["Auth"], "summary": "Usuário atual", "security": [{ "cookieSession": [] }, { "bearerAuth": [] }], "responses": { "200": { "description": "Usuário e salão" }, "401": { "$ref": "#/components/responses/Unauthorized" } } } },
    "/auth/plans-public": { "get": { "tags": ["Auth"], "summary": "Planos publicados", "responses": { "200": { "description": "Catálogo público" } } } },
    "/auth/register-salon": { "post": { "tags": ["Auth"], "summary": "Cadastra um salão", "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RegisterSalonRequest" } } } }, "responses": { "201": { "description": "Salão pendente de pagamento" }, "400": { "$ref": "#/components/responses/BadRequest" }, "409": { "$ref": "#/components/responses/Conflict" } } } },
    "/salon/appointments": { "get": { "tags": ["Salon"], "summary": "Lista agenda", "security": [{ "cookieSession": [] }, { "bearerAuth": [] }], "responses": { "200": { "description": "Agendamentos do salão" }, "401": { "$ref": "#/components/responses/Unauthorized" }, "402": { "$ref": "#/components/responses/PaymentRequired" } } } },
    "/salon/clients": { "get": { "tags": ["Salon"], "summary": "Lista clientes", "security": [{ "cookieSession": [] }, { "bearerAuth": [] }], "responses": { "200": { "description": "Clientes do tenant" } } } },
    "/salon/comandas": { "get": { "tags": ["Salon"], "summary": "Lista comandas", "security": [{ "cookieSession": [] }, { "bearerAuth": [] }], "responses": { "200": { "description": "Comandas do salão" } } } },
    "/salon/packages": { "get": { "tags": ["Salon"], "summary": "Lista pacotes vendidos", "security": [{ "cookieSession": [] }, { "bearerAuth": [] }], "responses": { "200": { "description": "Pacotes e utilização" } } } },
    "/salon/cashier/status": { "get": { "tags": ["Salon"], "summary": "Status do caixa", "security": [{ "cookieSession": [] }, { "bearerAuth": [] }], "responses": { "200": { "description": "Caixa atual" } } } },
    "/salon/financial/summary": { "get": { "tags": ["Salon"], "summary": "Resumo financeiro", "security": [{ "cookieSession": [] }, { "bearerAuth": [] }], "responses": { "200": { "description": "Indicadores financeiros" } } } },
    "/salon/billing/subscribe": { "post": { "tags": ["Salon"], "summary": "Gera checkout de assinatura", "description": "Usa o provedor configurado no Admin: Mercado Pago, InfinitePay avulso ou Woovi (Pix avulso/Pix Automático). A resposta Woovi pode conter link ou qrCode (EMV).", "security": [{ "cookieSession": [] }, { "bearerAuth": [] }], "requestBody": { "content": { "application/json": { "schema": { "type": "object", "properties": { "planId": { "type": "string" }, "email": { "type": "string", "format": "email" } } } } } }, "responses": { "200": { "description": "Checkout criado" }, "400": { "$ref": "#/components/responses/BadRequest" }, "401": { "$ref": "#/components/responses/Unauthorized" }, "503": { "description": "Provedor de pagamento não configurado" } } } },
    "/public/salon/{salonId}": { "get": { "tags": ["Public"], "summary": "Perfil público", "parameters": [{ "$ref": "#/components/parameters/SalonId" }], "responses": { "200": { "description": "Dados públicos do salão" }, "404": { "$ref": "#/components/responses/NotFound" } } } },
    "/public/salon/{salonId}/availability": { "get": { "tags": ["Public"], "summary": "Horários disponíveis", "parameters": [{ "$ref": "#/components/parameters/SalonId" }], "responses": { "200": { "description": "Agenda disponível" } } } },
    "/public/salon/{salonId}/book": { "post": { "tags": ["Public"], "summary": "Cria reserva pública", "parameters": [{ "$ref": "#/components/parameters/SalonId" }], "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["clientName", "serviceId", "startAt"], "properties": { "clientName": { "type": "string" }, "serviceId": { "type": "string" }, "professionalId": { "type": "string" }, "startAt": { "type": "string", "format": "date-time" } } } } } }, "responses": { "201": { "description": "Reserva criada" }, "409": { "$ref": "#/components/responses/Conflict" }, "429": { "$ref": "#/components/responses/RateLimited" } } } },
    "/public/whatsapp/webhook": { "post": { "tags": ["Public"], "summary": "Webhook WhatsApp assinado", "responses": { "200": { "description": "Evento aceito" }, "401": { "$ref": "#/components/responses/Unauthorized" } } } },
    "/infinitepay/webhook": { "post": { "tags": ["Public"], "summary": "Webhook InfinitePay Checkout", "description": "O evento é confirmado server-to-server pelo endpoint payment_check antes de ativar uma assinatura.", "responses": { "200": { "description": "Pagamento confirmado" }, "400": { "$ref": "#/components/responses/BadRequest" }, "503": { "description": "InfinitePay não configurada" } } } },
    "/woovi/webhook": { "post": { "tags": ["Public"], "summary": "Webhook Woovi", "description": "Valida x-webhook-signature com RSA e processa apenas cobranças concluídas da Woovi.", "parameters": [{ "name": "x-webhook-signature", "in": "header", "required": true, "schema": { "type": "string" } }], "responses": { "200": { "description": "Evento aceito" }, "400": { "$ref": "#/components/responses/BadRequest" }, "401": { "$ref": "#/components/responses/Unauthorized" } } } },
    "/mcp": { "post": { "tags": ["MCP"], "summary": "JSON-RPC MCP", "description": "Use Authorization: Bearer blz_live_<salonId>.<secret>.", "security": [{ "bearerAuth": [] }], "responses": { "200": { "description": "Resposta JSON-RPC" }, "401": { "$ref": "#/components/responses/Unauthorized" }, "429": { "$ref": "#/components/responses/RateLimited" } } } },
    "/admin/dashboard": { "get": { "tags": ["Admin"], "summary": "Dashboard SaaS", "security": [{ "cookieSession": [] }, { "bearerAuth": [] }], "responses": { "200": { "description": "Indicadores globais" }, "403": { "$ref": "#/components/responses/Forbidden" } } } }
  },
  "components": {
    "securitySchemes": { "cookieSession": { "type": "apiKey", "in": "cookie", "name": "belezalink_session" }, "bearerAuth": { "type": "http", "scheme": "bearer", "bearerFormat": "Salon PAT" } },
    "parameters": { "SalonId": { "name": "salonId", "in": "path", "required": true, "schema": { "type": "string" } } },
    "responses": { "BadRequest": { "description": "Payload inválido" }, "Unauthorized": { "description": "Sessão ou token inválido" }, "Forbidden": { "description": "Permissão insuficiente" }, "PaymentRequired": { "description": "Plano sem acesso ativo" }, "NotFound": { "description": "Recurso não encontrado" }, "Conflict": { "description": "Conflito de regra de negócio" }, "RateLimited": { "description": "Limite de requisições atingido" } },
    "schemas": { "LoginRequest": { "type": "object", "required": ["email", "password"], "properties": { "email": { "type": "string", "format": "email" }, "password": { "type": "string", "format": "password" } } }, "RegisterSalonRequest": { "type": "object", "required": ["salonName", "ownerName", "email", "password"], "properties": { "salonName": { "type": "string" }, "ownerName": { "type": "string" }, "email": { "type": "string", "format": "email" }, "password": { "type": "string", "minLength": 10 }, "phone": { "type": "string" }, "planId": { "type": "string" } } } }
  }
}
