{"openapi":"3.1.0","info":{"title":"ChatSAC Nexus — Public API","version":"1.0.0","description":"Public REST API para integrações de tenants do ChatSAC Nexus.\n\n**Autenticação:** todas as requisições precisam do header `Authorization: Bearer nxs_<seu-token>`. Tokens são gerados no painel do Nexus em Settings → API Keys.\n\n**Rate limit:** 50 requisições por segundo + 2500 requisições por minuto, por token. Quando o limite é atingido, a API retorna `429 Too Many Requests`.\n\n**Erros:** seguem o formato RFC 7807 (Problem Details for HTTP APIs).","contact":{"name":"ChatSAC","url":"https://chatsac.com"}},"servers":[{"url":"https://developers.chatsac.com","description":"Production"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"nxs_<43 chars>","description":"API token gerado no painel do Nexus. Formato `nxs_<43 chars base64url>`."}},"schemas":{"Problem":{"type":"object","description":"Erro no formato RFC 7807 (Problem Details).","properties":{"type":{"type":"string","format":"uri","example":"https://docs.chatsac.com/errors/not-found"},"title":{"type":"string","example":"Resource Not Found"},"status":{"type":"integer","example":404},"detail":{"type":"string","example":"Contact 'abc' not found"},"instance":{"type":"string","example":"/api/v1/contacts/abc"},"request_id":{"type":"string","example":"req_a1b2c3d4"},"code":{"type":"string","example":"NOT_FOUND"}},"required":["type","title","status","detail"]},"SuccessEnvelope":{"type":"object","properties":{"success":{"type":"boolean","const":true},"data":{},"meta":{"type":"object","properties":{"timestamp":{"type":"string","format":"date-time"},"version":{"type":"string","example":"2.0"},"page":{"type":"integer"},"limit":{"type":"integer"},"total":{"type":"integer"}}}},"required":["success","data"]},"Contact":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"systemId":{"type":"string"},"phone":{"type":"string","example":"5511999990001"},"name":{"type":"string","nullable":true},"email":{"type":"string","format":"email","nullable":true},"avatarUrl":{"type":"string","format":"uri","nullable":true},"tagId":{"type":"array","items":{"type":"string","format":"uuid"},"description":"Sempre array. Vazio se o contato não tem etiqueta."},"tags":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"name":{"type":"string"}},"required":["id","name"]}},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"}}},"Conversation":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"contactId":{"type":"string","format":"uuid"},"status":{"type":"string","enum":["waiting","active","closed","after-hours"]},"type":{"type":"string","enum":["bot","manual","group"]},"priority":{"type":"string","enum":["low","medium","high","urgent"]},"channelId":{"type":"string","format":"uuid","nullable":true},"teamId":{"type":"string","format":"uuid","nullable":true},"lastMessageAt":{"type":"string","format":"date-time","nullable":true},"createdAt":{"type":"string","format":"date-time"}}},"Message":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"conversationId":{"type":"string","format":"uuid"},"senderType":{"type":"string","enum":["customer","agent","bot","system"]},"content":{"type":"string"},"channel":{"type":"string"},"mediaType":{"type":"string","nullable":true},"mediaUrl":{"type":"string","nullable":true},"isInternal":{"type":"boolean"},"status":{"type":"string"},"createdAt":{"type":"string","format":"date-time"}}}},"responses":{"Unauthorized":{"description":"Token ausente, inválido ou revogado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"NotFound":{"description":"Recurso não encontrado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"ValidationError":{"description":"Validação do payload falhou","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"RateLimited":{"description":"Rate limit excedido (50/s ou 2500/min)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}},"tags":[{"name":"System","description":"Health check e configurações do sistema"},{"name":"Contacts","description":"CRUD de contatos, atributos e tags"},{"name":"Chats","description":"Gestão de conversas, mensagens e agendamento"},{"name":"Messaging","description":"Envio de mensagens via WhatsApp"},{"name":"Messages","description":"Endpoint unificado de envio (POST /messages)"},{"name":"Tags","description":"CRUD de tags"},{"name":"Channels","description":"Canais de comunicação"},{"name":"Users","description":"Usuários e perfis"},{"name":"Chatbots","description":"Fluxos de chatbot"},{"name":"Deals","description":"CRM — deals e propriedades customizadas"},{"name":"Pipelines","description":"CRM — pipelines e estágios"},{"name":"Teams","description":"Times, membros e permissões"},{"name":"Templates","description":"Quick answers e templates WhatsApp"},{"name":"Scripts","description":"Automações e execuções agendadas"},{"name":"ServiceTime","description":"Regras de horário de atendimento"},{"name":"Campaigns","description":"Campanhas e playbooks"},{"name":"CSAT","description":"Satisfação do cliente"},{"name":"Calls","description":"Histórico de chamadas e telefonia"},{"name":"Analytics","description":"Dashboard, métricas e lead scoring"},{"name":"API Tokens","description":"Gerenciamento de API keys"}],"paths":{"/health":{"get":{"tags":["System"],"summary":"Health check","security":[],"responses":{"200":{"description":"OK"}}}},"/api/v1/contacts":{"get":{"tags":["Contacts"],"summary":"List contacts","parameters":[{"name":"page","in":"query","schema":{"type":"integer","minimum":1,"default":1}},{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":100,"default":25}},{"name":"search","in":"query","schema":{"type":"string"}},{"name":"tagId","in":"query","schema":{"type":"string","format":"uuid"},"description":"Filtra contatos que têm esta etiqueta (o contato pode ter outras). UUID inexistente devolve lista vazia."},{"name":"sort","in":"query","schema":{"type":"string","enum":["name","createdAt","updatedAt"],"default":"createdAt"}},{"name":"order","in":"query","schema":{"type":"string","enum":["asc","desc"],"default":"desc"}}],"responses":{"200":{"description":"Lista de contatos","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"429":{"$ref":"#/components/responses/RateLimited"}}},"post":{"tags":["Contacts"],"summary":"Create contact","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["phone"],"properties":{"phone":{"type":"string","example":"+55 11 99999-0001"},"name":{"type":"string","nullable":true},"email":{"type":"string","format":"email","nullable":true},"avatarUrl":{"type":"string","format":"uri","nullable":true}}}}}},"responses":{"201":{"description":"Contato criado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"409":{"description":"Contato já existe com esse telefone"},"422":{"$ref":"#/components/responses/ValidationError"}}}},"/api/v1/contacts/{id}":{"get":{"tags":["Contacts"],"summary":"Get contact by ID","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Contato","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/contacts/number/{number}":{"get":{"tags":["Contacts"],"summary":"Lookup contact by phone number","parameters":[{"name":"number","in":"path","required":true,"schema":{"type":"string"},"example":"+5511999990001"}],"responses":{"200":{"description":"Contato","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"},"422":{"$ref":"#/components/responses/ValidationError"}}}},"/api/v1/chats/list":{"get":{"tags":["Chats"],"summary":"List chats","parameters":[{"name":"page","in":"query","schema":{"type":"integer","minimum":1,"default":1}},{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":100,"default":25}},{"name":"status","in":"query","schema":{"type":"string","enum":["waiting","active","closed","after-hours"]}},{"name":"channelId","in":"query","schema":{"type":"string","format":"uuid"}},{"name":"contactId","in":"query","schema":{"type":"string","format":"uuid"}},{"name":"priority","in":"query","schema":{"type":"string","enum":["low","medium","high","urgent"]}},{"name":"tagId","in":"query","schema":{"type":"string","format":"uuid"},"description":"Filtra conversas cujo contato tem esta etiqueta."}],"responses":{"200":{"description":"Lista de chats","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/chats/{id}":{"get":{"tags":["Chats"],"summary":"Get chat by ID","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Chat detail (com últimas 50 mensagens)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/chats/{id}/messages":{"get":{"tags":["Chats"],"summary":"List messages of a chat (cursor-paginated)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":100,"default":50}},{"name":"cursor","in":"query","schema":{"type":"string","format":"date-time"},"description":"ISO timestamp do último item da página anterior"},{"name":"includeInternal","in":"query","schema":{"type":"boolean","default":false}}],"responses":{"200":{"description":"Mensagens","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/messages":{"post":{"tags":["Messages"],"summary":"Send message (unified)","description":"Endpoint unificado de envio de mensagens WhatsApp. O campo `type` define o formato do payload. Identifique o destinatário com **um** entre `conversationId`, `chatId` (alias), `contactId`, `phone` (alias `to`).\n\n**Tipos suportados:**\n- `text` — `text` (string ou `{body, previewUrl?}`)\n- `image` / `video` / `document` — `<type>: { link, caption?, filename? }`\n- `audio` — anexo de áudio: `audio: { link }`\n- `voice` — nota de voz (PTT): `voice: { link }`\n- `sticker` — `sticker: { link }`\n- `template` — `template: { name, language, components? | variables? }`\n- `location` — `location: { latitude, longitude, name?, address? }`\n- `contacts` — `contacts: [{ name: { formatted_name, ... }, phones?, emails?, ... }]`\n- `interactive` — `interactive: { type: 'buttons'|'list'|'cta_url', body, header?, footer?, ... }`\n  - `buttons`: `buttons: [{ id?, title }]` (1 a 3)\n  - `list`: `buttonText`, `sections: [{ title?, rows: [{ id, title, description? }] }]`\n  - `cta_url`: `cta: { url, display_text }`\n  - `header` aceita `{ type: 'text', text }` ou `{ type: 'image'|'video'|'document', link, filename? }`\n- `action_card` — `action_card: { id }` (resolve respostas rápidas pré-cadastradas)\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type"],"properties":{"type":{"type":"string","enum":["text","image","video","audio","voice","document","sticker","template","location","contacts","interactive","action_card"],"example":"text"},"conversationId":{"type":"string","format":"uuid","description":"UUID da conversa."},"chatId":{"type":"string","format":"uuid","description":"Alias de conversationId."},"contactId":{"type":"string","format":"uuid","description":"UUID do contato."},"phone":{"type":"string","description":"Telefone E.164. Cria contato e conversa se não existirem.","example":"5511999990001"},"to":{"type":"string","description":"Alias de phone."},"channelId":{"type":"string","format":"uuid","description":"Override do canal padrão."},"text":{"description":"Para type=text. String ou { body, previewUrl? }.","oneOf":[{"type":"string","maxLength":4096},{"type":"object","properties":{"body":{"type":"string","maxLength":4096},"previewUrl":{"type":"boolean"}}}]},"image":{"type":"object","description":"{ link, caption? }","properties":{"link":{"type":"string","format":"uri"},"caption":{"type":"string","maxLength":1024}}},"video":{"type":"object","description":"{ link, caption? }"},"audio":{"type":"object","description":"{ link }"},"voice":{"type":"object","description":"{ link } — envia como nota de voz (PTT)."},"document":{"type":"object","description":"{ link, caption?, filename? }"},"sticker":{"type":"object","description":"{ link } — preferencialmente .webp 512x512."},"template":{"type":"object","description":"{ name, language, components? | variables? }","properties":{"name":{"type":"string"},"language":{"type":"string","example":"pt_BR"},"components":{"type":"array","items":{"type":"object"}},"variables":{"type":"array","items":{"type":"string"}}}},"location":{"type":"object","properties":{"latitude":{"type":"number","example":-23.5505},"longitude":{"type":"number","example":-46.6333},"name":{"type":"string"},"address":{"type":"string"}}},"contacts":{"type":"array","description":"Array de vCards no formato Meta.","items":{"type":"object"}},"interactive":{"type":"object","description":"Mensagem interativa (buttons | list | cta_url) com header/footer opcionais.","properties":{"type":{"type":"string","enum":["buttons","list","cta_url"]},"body":{"description":"Texto do corpo (string ou { text }).","oneOf":[{"type":"string"},{"type":"object"}]},"footer":{"description":"Texto do rodapé (string ou { text }).","oneOf":[{"type":"string"},{"type":"object"}]},"header":{"type":"object","description":"{ type: 'text'|'image'|'video'|'document', text? | link?, filename? }"},"buttons":{"type":"array","description":"Para buttons: [{ id?, title }] (1 a 3).","items":{"type":"object"}},"buttonText":{"type":"string","description":"Para list: rótulo do botão que abre a lista."},"sections":{"type":"array","description":"Para list: [{ title?, rows: [...] }].","items":{"type":"object"}},"cta":{"type":"object","description":"Para cta_url: { url, display_text }."}}},"action_card":{"description":"{ id } ou string com o id.","oneOf":[{"type":"string","format":"uuid"},{"type":"object","properties":{"id":{"type":"string","format":"uuid"}}}]}}}}}},"responses":{"202":{"description":"Mensagem aceita pra envio.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"description":"Destinatário/conversa/contato não encontrado."},"422":{"$ref":"#/components/responses/ValidationError"}}}},"/api/v1/messages/{id}":{"delete":{"tags":["Messages"],"summary":"Soft-delete a message","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Mensagem marcada como deletada.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/chats/send-text":{"post":{"tags":["Chats"],"summary":"Send a WhatsApp text message","deprecated":true,"description":"**Deprecated** — prefira `POST /api/v1/messages` com `type: 'text'`. Mantido como alias.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["conversationId","message"],"properties":{"conversationId":{"type":"string","format":"uuid"},"message":{"type":"string","maxLength":4096},"previewUrl":{"type":"boolean","default":false},"channelId":{"type":"string","format":"uuid","description":"Override do canal padrão da conversation"}}}}}},"responses":{"202":{"description":"Mensagem enfileirada (sent)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/ValidationError"}}}},"/api/v1/chats/create-new":{"post":{"tags":["Chats"],"summary":"Open a new chat with a contact and optionally send first message","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["phone","message"],"properties":{"phone":{"type":"string","example":"+55 11 99999-0001"},"message":{"type":"string"},"channelId":{"type":"string","format":"uuid"},"contactName":{"type":"string","nullable":true}}}}}},"responses":{"201":{"description":"Chat criado + mensagem enviada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/ValidationError"}}}},"/api/v1/tags":{"get":{"tags":["Tags"],"summary":"List workspace tags","description":"Catálogo canônico (`tags`) do workspace, com contactCount. Tags globais (system_id nulo) entram na lista.","parameters":[{"name":"page","in":"query","schema":{"type":"integer","minimum":1}},{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":100}}],"responses":{"200":{"description":"Lista de tags com contactCount","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/channel/list":{"get":{"tags":["Channels"],"summary":"List channels","description":"Lista canais do tenant. Tokens sensíveis são omitidos da resposta.","responses":{"200":{"description":"Lista de canais","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/users":{"get":{"tags":["Users"],"summary":"List users","description":"Lista todos os usuários/perfis do sistema.","responses":{"200":{"description":"Lista de usuários","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/users/me":{"get":{"tags":["Users"],"summary":"Current user profile","description":"Retorna o perfil do usuário autenticado (apenas JWT, não funciona com API key).","responses":{"200":{"description":"Perfil do usuário","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/users/{id}":{"get":{"tags":["Users"],"summary":"User detail","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Perfil do usuário","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"put":{"tags":["Users"],"summary":"Update user profile","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"phone":{"type":"string","nullable":true},"email":{"type":"string","format":"email","nullable":true},"avatarUrl":{"type":"string","format":"uri","nullable":true},"specialty":{"type":"string","nullable":true}}}}}},"responses":{"200":{"description":"Perfil atualizado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/chatbots":{"get":{"tags":["Chatbots"],"summary":"List chatbot flows","description":"Lista fluxos de chatbot do sistema. Nodes/edges/variables são omitidos na listagem.","responses":{"200":{"description":"Lista de chatbots","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/chatbots/{id}":{"get":{"tags":["Chatbots"],"summary":"Chatbot flow detail","description":"Retorna o fluxo completo com nodes, edges e variáveis.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Fluxo completo","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/deals":{"get":{"tags":["Deals"],"summary":"List deals","description":"Lista deals paginados. Filtráveis por pipeline, estágio ou contato.","parameters":[{"name":"page","in":"query","schema":{"type":"integer","default":1}},{"name":"limit","in":"query","schema":{"type":"integer","default":25,"maximum":100}},{"name":"pipelineId","in":"query","schema":{"type":"string","format":"uuid"}},{"name":"stageId","in":"query","schema":{"type":"string","format":"uuid"}},{"name":"contactId","in":"query","schema":{"type":"string","format":"uuid"}},{"name":"sort","in":"query","schema":{"type":"string","enum":["createdAt","updatedAt","value","title"]}},{"name":"order","in":"query","schema":{"type":"string","enum":["asc","desc"]}}],"responses":{"200":{"description":"Lista de deals com paginação","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}},"post":{"tags":["Deals"],"summary":"Create deal","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["title","pipelineId","stageId"],"properties":{"title":{"type":"string"},"value":{"type":"number","default":0},"pipelineId":{"type":"string","format":"uuid"},"stageId":{"type":"string","format":"uuid"},"contactId":{"type":"string","format":"uuid","nullable":true},"phone":{"type":"string","nullable":true},"notes":{"type":"string","nullable":true}}}}}},"responses":{"201":{"description":"Deal criado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/ValidationError"}}}},"/api/v1/deals/pipelines":{"get":{"tags":["Deals"],"summary":"List pipelines with stages","description":"Lista todos os pipelines do sistema com seus estágios ordenados por posição.","responses":{"200":{"description":"Pipelines com estágios","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/deals/{id}":{"get":{"tags":["Deals"],"summary":"Deal detail with stage history","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Deal com histórico de estágios","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"put":{"tags":["Deals"],"summary":"Update deal","description":"Atualiza deal. Se stageId mudar, registra histórico automaticamente. Estágios win/loss setam closedAt.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"title":{"type":"string"},"value":{"type":"number"},"stageId":{"type":"string","format":"uuid"},"contactId":{"type":"string","format":"uuid","nullable":true},"phone":{"type":"string","nullable":true},"notes":{"type":"string","nullable":true},"lossReason":{"type":"string","nullable":true}}}}}},"responses":{"200":{"description":"Deal atualizado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"},"422":{"$ref":"#/components/responses/ValidationError"}}},"delete":{"tags":["Deals"],"summary":"Delete deal","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Deal deletado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/teams":{"get":{"tags":["Teams"],"summary":"List teams","responses":{"200":{"description":"Lista de times","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}},"post":{"tags":["Teams"],"summary":"Create team","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["name"],"properties":{"name":{"type":"string"},"description":{"type":"string","nullable":true}}}}}},"responses":{"201":{"description":"Time criado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/teams/{id}":{"get":{"tags":["Teams"],"summary":"Team detail with members","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Time com lista de membros","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"put":{"tags":["Teams"],"summary":"Update team","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"description":{"type":"string","nullable":true}}}}}},"responses":{"200":{"description":"Time atualizado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/teams/{id}/members":{"post":{"tags":["Teams"],"summary":"Add member to team","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["userId"],"properties":{"userId":{"type":"string","format":"uuid"}}}}}},"responses":{"201":{"description":"Membro adicionado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/teams/{id}/members/{memberId}":{"delete":{"tags":["Teams"],"summary":"Remove member from team","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"memberId","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Membro removido","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/contacts/{id}/attributes":{"get":{"tags":["Contacts"],"summary":"List contact attributes","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Atributos do contato","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"post":{"tags":["Contacts"],"summary":"Upsert contact attributes","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["attributes"],"properties":{"attributes":{"type":"array","items":{"type":"object","required":["key","name","value"],"properties":{"key":{"type":"string"},"name":{"type":"string"},"value":{"type":"string"},"description":{"type":"string","nullable":true}}}}}}}}},"responses":{"200":{"description":"Atributos upserted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/contacts/{id}/attributes/{key}":{"get":{"tags":["Contacts"],"summary":"Get contact attribute by key","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"key","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Atributo","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/contacts/{id}/tags":{"get":{"tags":["Contacts"],"summary":"List contact tags","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Tags do contato","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"put":{"tags":["Contacts"],"summary":"Replace all tags on contact","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["tagIds"],"properties":{"tagIds":{"type":"array","items":{"type":"string","format":"uuid"}}}}}}},"responses":{"200":{"description":"Tags substituídas","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/contacts/{id}/tags/add":{"put":{"tags":["Contacts"],"summary":"Add tags to contact (incremental)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["tagIds"],"properties":{"tagIds":{"type":"array","items":{"type":"string","format":"uuid"}}}}}}},"responses":{"200":{"description":"Tags adicionadas","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/contacts/{id}/tags/remove":{"put":{"tags":["Contacts"],"summary":"Remove tags from contact","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["tagIds"],"properties":{"tagIds":{"type":"array","items":{"type":"string","format":"uuid"}}}}}}},"responses":{"200":{"description":"Tags removidas","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/chats/list-lite":{"post":{"tags":["Chats"],"summary":"Lightweight conversation list","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"page":{"type":"integer","default":1},"limit":{"type":"integer","default":100},"status":{"type":"string"}}}}}},"responses":{"200":{"description":"Lista resumida","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/chats/count":{"post":{"tags":["Chats"],"summary":"Count conversations by filters","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string"},"assignedTo":{"type":"string","format":"uuid"},"channelId":{"type":"string","format":"uuid"},"teamId":{"type":"string","format":"uuid"}}}}}},"responses":{"200":{"description":"Contagem","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/chats/finalize":{"post":{"tags":["Chats"],"summary":"Bulk finalize conversations","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string"},"assignedTo":{"type":"string","format":"uuid"},"channelId":{"type":"string","format":"uuid"},"teamId":{"type":"string","format":"uuid"}}}}}},"responses":{"200":{"description":"Conversas finalizadas","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/chats/{id}/finalize":{"post":{"tags":["Chats"],"summary":"Finalize a single chat","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Chat finalizado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/chats/{id}/transfer":{"post":{"tags":["Chats"],"summary":"Transfer chat to agent or team","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"assignedTo":{"type":"string","format":"uuid","nullable":true},"teamId":{"type":"string","format":"uuid","nullable":true}}}}}},"responses":{"200":{"description":"Chat transferido","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/chats/{id}/attributes":{"get":{"tags":["Chats"],"summary":"List conversation attributes","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Atributos","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"post":{"tags":["Chats"],"summary":"Upsert conversation attributes","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["attributes"],"properties":{"attributes":{"type":"array","items":{"type":"object","properties":{"key":{"type":"string"},"name":{"type":"string"},"value":{"type":"string"}}}}}}}}},"responses":{"200":{"description":"Atributos upserted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/chats/{id}/attributes/{key}":{"get":{"tags":["Chats"],"summary":"Get conversation attribute by key","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"key","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Atributo","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/chats/messages/scheduler":{"post":{"tags":["Chats"],"summary":"Schedule a message","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["conversationId","channelId","contactId","contactPhone","title","scheduledAt","messageType"],"properties":{"conversationId":{"type":"string","format":"uuid"},"channelId":{"type":"string","format":"uuid"},"contactId":{"type":"string","format":"uuid"},"contactPhone":{"type":"string"},"title":{"type":"string"},"scheduledAt":{"type":"string","format":"date-time"},"messageType":{"type":"string","enum":["text","template"]},"textContent":{"type":"string","nullable":true},"templateName":{"type":"string","nullable":true}}}}}},"responses":{"201":{"description":"Mensagem agendada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/chats/messages/scheduler/list":{"post":{"tags":["Chats"],"summary":"List scheduled messages","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"page":{"type":"integer"},"limit":{"type":"integer"},"status":{"type":"string"},"conversationId":{"type":"string","format":"uuid"}}}}}},"responses":{"200":{"description":"Mensagens agendadas","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/chats/messages/scheduler/{scheduleId}":{"get":{"tags":["Chats"],"summary":"Get scheduled message by ID","parameters":[{"name":"scheduleId","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Mensagem agendada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"delete":{"tags":["Chats"],"summary":"Cancel scheduled message","parameters":[{"name":"scheduleId","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Mensagem cancelada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/chats/{id}/notes":{"get":{"tags":["Chats"],"summary":"List conversation notes","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Notas","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}},"post":{"tags":["Chats"],"summary":"Add note to conversation","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["content"],"properties":{"content":{"type":"string"}}}}}},"responses":{"201":{"description":"Nota criada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/chats/{id}/notes/{noteId}":{"delete":{"tags":["Chats"],"summary":"Delete conversation note","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"noteId","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Nota deletada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/chats/pinned":{"get":{"tags":["Chats"],"summary":"List pinned conversations","responses":{"200":{"description":"Conversas fixadas","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/chats/{id}/pin":{"post":{"tags":["Chats"],"summary":"Pin a conversation","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Conversa fixada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}},"delete":{"tags":["Chats"],"summary":"Unpin a conversation","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Conversa desfixada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/chats/{id}/classification":{"get":{"tags":["Chats"],"summary":"Get conversation classification (sentiment, intent)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Classificação","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/general-settings":{"get":{"tags":["System"],"summary":"Get company settings","responses":{"200":{"description":"Configurações da empresa","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}},"post":{"tags":["System"],"summary":"Update company settings","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"companyName":{"type":"string"},"logoUrl":{"type":"string","format":"uri","nullable":true},"timezone":{"type":"string"}}}}}},"responses":{"200":{"description":"Configurações atualizadas","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/quick-answers":{"get":{"tags":["Templates"],"summary":"List quick replies","responses":{"200":{"description":"Respostas rápidas","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/quick-answers/{id}":{"get":{"tags":["Templates"],"summary":"Quick reply detail","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Resposta rápida","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/templates":{"get":{"tags":["Templates"],"summary":"List WhatsApp templates","responses":{"200":{"description":"Templates","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/templates/{id}":{"get":{"tags":["Templates"],"summary":"WhatsApp template detail","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Template","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/service-time-rules":{"get":{"tags":["ServiceTime"],"summary":"List business hours rules","responses":{"200":{"description":"Regras de horário","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/check-is-service-time":{"get":{"tags":["ServiceTime"],"summary":"Check if current time is within business hours","responses":{"200":{"description":"Resultado com dia, hora e regra aplicada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/scripts":{"get":{"tags":["Scripts"],"summary":"List automation scripts","parameters":[{"name":"page","in":"query","schema":{"type":"integer","default":1}},{"name":"limit","in":"query","schema":{"type":"integer","default":25}},{"name":"isActive","in":"query","schema":{"type":"boolean"}}],"responses":{"200":{"description":"Scripts","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/scripts/events":{"get":{"tags":["Scripts"],"summary":"List available trigger event types","responses":{"200":{"description":"Tipos de evento","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/scripts/{id}":{"get":{"tags":["Scripts"],"summary":"Script detail (includes code)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Script","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"delete":{"tags":["Scripts"],"summary":"Delete script","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Script deletado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/scripts/scheduler/list":{"post":{"tags":["Scripts"],"summary":"List script executions","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"page":{"type":"integer"},"limit":{"type":"integer"},"scriptId":{"type":"string","format":"uuid"},"status":{"type":"string"}}}}}},"responses":{"200":{"description":"Execuções","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/scripts/scheduler/{id}":{"delete":{"tags":["Scripts"],"summary":"Cancel scheduled script","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Execução cancelada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/pipelines":{"get":{"tags":["Pipelines"],"summary":"List pipelines","responses":{"200":{"description":"Pipelines","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}},"post":{"tags":["Pipelines"],"summary":"Create pipeline","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["name"],"properties":{"name":{"type":"string"},"description":{"type":"string","nullable":true}}}}}},"responses":{"201":{"description":"Pipeline criado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/pipelines/{id}":{"get":{"tags":["Pipelines"],"summary":"Pipeline detail with stages","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Pipeline com estágios","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"put":{"tags":["Pipelines"],"summary":"Update pipeline","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"description":{"type":"string","nullable":true}}}}}},"responses":{"200":{"description":"Pipeline atualizado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"delete":{"tags":["Pipelines"],"summary":"Delete pipeline (fails if has deals)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Pipeline deletado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"},"409":{"description":"Pipeline tem deals ativos"}}}},"/api/v1/pipelines/{id}/stages":{"get":{"tags":["Pipelines"],"summary":"List stages of a pipeline","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Estágios","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}},"post":{"tags":["Pipelines"],"summary":"Create stage","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["title"],"properties":{"title":{"type":"string"},"color":{"type":"string"},"position":{"type":"integer"},"isWinStage":{"type":"boolean"},"isLossStage":{"type":"boolean"}}}}}},"responses":{"201":{"description":"Estágio criado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/pipelines/{pipelineId}/stages/{stageId}":{"put":{"tags":["Pipelines"],"summary":"Update stage","parameters":[{"name":"pipelineId","in":"path","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"stageId","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"title":{"type":"string"},"color":{"type":"string"},"position":{"type":"integer"}}}}}},"responses":{"200":{"description":"Estágio atualizado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"delete":{"tags":["Pipelines"],"summary":"Delete stage (fails if has deals)","parameters":[{"name":"pipelineId","in":"path","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"stageId","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Estágio deletado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/deals/{id}/move":{"post":{"tags":["Deals"],"summary":"Move deal to stage (records history)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["stageId"],"properties":{"stageId":{"type":"string","format":"uuid"}}}}}},"responses":{"200":{"description":"Deal movido","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/deals/{id}/close":{"post":{"tags":["Deals"],"summary":"Close deal as won or lost","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["won"],"properties":{"won":{"type":"boolean"},"lossReason":{"type":"string","nullable":true}}}}}},"responses":{"200":{"description":"Deal fechado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/deals/{id}/history":{"get":{"tags":["Deals"],"summary":"Deal stage movement history","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Histórico","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/deals/custom-properties":{"get":{"tags":["Deals"],"summary":"List custom property definitions","responses":{"200":{"description":"Propriedades","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}},"post":{"tags":["Deals"],"summary":"Create custom property","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["name"],"properties":{"name":{"type":"string"},"objectType":{"type":"string","default":"deal"},"propertyType":{"type":"string","enum":["text","number","date","select","multi_select","boolean"]},"options":{"type":"array"}}}}}},"responses":{"201":{"description":"Propriedade criada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/deals/{id}/custom-properties":{"put":{"tags":["Deals"],"summary":"Set custom property values on deal","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["values"],"properties":{"values":{"type":"array","items":{"type":"object","properties":{"propertyId":{"type":"string","format":"uuid"},"value":{"type":"string"}}}}}}}}},"responses":{"200":{"description":"Valores setados","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/teams/{id}/permissions":{"get":{"tags":["Teams"],"summary":"List team permissions","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Permissões","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"put":{"tags":["Teams"],"summary":"Bulk upsert team permissions","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["permissions"],"properties":{"permissions":{"type":"array","items":{"type":"object","properties":{"permissionKey":{"type":"string"},"allowed":{"type":"boolean"},"scope":{"type":"string","nullable":true}}}}}}}}},"responses":{"200":{"description":"Permissões atualizadas","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/campaigns":{"get":{"tags":["Campaigns"],"summary":"List campaigns","parameters":[{"name":"page","in":"query","schema":{"type":"integer"}},{"name":"limit","in":"query","schema":{"type":"integer"}},{"name":"status","in":"query","schema":{"type":"string"}}],"responses":{"200":{"description":"Campanhas","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}},"post":{"tags":["Campaigns"],"summary":"Create campaign (draft)","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["name"],"properties":{"name":{"type":"string"},"description":{"type":"string"},"channelType":{"type":"string","enum":["whatsapp","email","sms"]},"templateName":{"type":"string"},"sendType":{"type":"string","enum":["immediate","scheduled"]},"scheduledAt":{"type":"string","format":"date-time"}}}}}},"responses":{"201":{"description":"Campanha criada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/campaigns/{id}":{"get":{"tags":["Campaigns"],"summary":"Campaign detail","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Campanha","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"put":{"tags":["Campaigns"],"summary":"Update campaign (draft only)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"templateName":{"type":"string"},"sendType":{"type":"string"}}}}}},"responses":{"200":{"description":"Campanha atualizada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"409":{"description":"Only draft campaigns"}}},"delete":{"tags":["Campaigns"],"summary":"Delete campaign (draft only)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Deletada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"409":{"description":"Only draft campaigns"}}}},"/api/v1/campaigns/{id}/cancel":{"post":{"tags":["Campaigns"],"summary":"Cancel scheduled campaign","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Cancelada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"409":{"description":"Only scheduled campaigns"}}}},"/api/v1/campaigns/{id}/recipients":{"get":{"tags":["Campaigns"],"summary":"List campaign recipients","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"page","in":"query","schema":{"type":"integer"}},{"name":"status","in":"query","schema":{"type":"string"}}],"responses":{"200":{"description":"Destinatários","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}},"post":{"tags":["Campaigns"],"summary":"Add recipients to campaign","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["recipients"],"properties":{"recipients":{"type":"array","items":{"type":"object","properties":{"contactPhone":{"type":"string"},"contactName":{"type":"string"}}}}}}}}},"responses":{"200":{"description":"Adicionados","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/campaigns/{id}/metrics":{"get":{"tags":["Campaigns"],"summary":"Campaign delivery metrics","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Métricas","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/playbooks":{"get":{"tags":["Campaigns"],"summary":"List playbooks","responses":{"200":{"description":"Playbooks","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/playbooks/{id}":{"get":{"tags":["Campaigns"],"summary":"Playbook detail","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Playbook","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/csat/config":{"get":{"tags":["CSAT"],"summary":"Get CSAT configuration","responses":{"200":{"description":"Config","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}},"put":{"tags":["CSAT"],"summary":"Update CSAT configuration","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"enabled":{"type":"boolean"},"messageType":{"type":"string","enum":["button","list","text"]},"autoSendOnClose":{"type":"boolean"},"askComment":{"type":"boolean"}}}}}},"responses":{"200":{"description":"Config atualizada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/csat/ratings":{"get":{"tags":["CSAT"],"summary":"List CSAT ratings","parameters":[{"name":"page","in":"query","schema":{"type":"integer"}},{"name":"assignedTo","in":"query","schema":{"type":"string","format":"uuid"}},{"name":"rating","in":"query","schema":{"type":"integer","minimum":1,"maximum":5}},{"name":"from","in":"query","schema":{"type":"string","format":"date-time"}},{"name":"to","in":"query","schema":{"type":"string","format":"date-time"}}],"responses":{"200":{"description":"Avaliações","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/csat/metrics":{"get":{"tags":["CSAT"],"summary":"Aggregated CSAT metrics","responses":{"200":{"description":"Métricas (média, NPS, distribuição)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/csat/metrics/by-agent":{"get":{"tags":["CSAT"],"summary":"CSAT metrics grouped by agent","responses":{"200":{"description":"Métricas por agente","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/csat/metrics/trend":{"get":{"tags":["CSAT"],"summary":"CSAT daily trend (last 90 days)","responses":{"200":{"description":"Tendência diária","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/calls":{"get":{"tags":["Calls"],"summary":"List call history","parameters":[{"name":"page","in":"query","schema":{"type":"integer"}},{"name":"limit","in":"query","schema":{"type":"integer"}},{"name":"direction","in":"query","schema":{"type":"string","enum":["inbound","outbound"]}}],"responses":{"200":{"description":"Chamadas","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/calls/{id}":{"get":{"tags":["Calls"],"summary":"Call detail","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Chamada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/calls/{id}/analysis":{"get":{"tags":["Calls"],"summary":"Call transcription and sentiment","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Análise","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/calls/{id}/notes":{"get":{"tags":["Calls"],"summary":"List call notes","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Notas","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}},"post":{"tags":["Calls"],"summary":"Add note to call","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["content"],"properties":{"content":{"type":"string"}}}}}},"responses":{"201":{"description":"Nota criada","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/telephony/providers":{"get":{"tags":["Calls"],"summary":"List telephony providers","responses":{"200":{"description":"Provedores","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/telephony/config":{"get":{"tags":["Calls"],"summary":"Tenant telephony configuration","responses":{"200":{"description":"Configuração (sem credentials)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/analytics/dashboard":{"get":{"tags":["Analytics"],"summary":"Dashboard KPIs (conversations, contacts, deals, CSAT)","responses":{"200":{"description":"KPIs","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/analytics/financial/settings":{"get":{"tags":["Analytics"],"summary":"Value metrics settings","responses":{"200":{"description":"Configurações de métricas","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}},"put":{"tags":["Analytics"],"summary":"Update value metrics settings","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"agentHourlyCost":{"type":"number"},"avgConversationTimeMinutes":{"type":"number"},"avgTicketValue":{"type":"number"},"conversionRate":{"type":"number"}}}}}},"responses":{"200":{"description":"Atualizado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/analytics/conversations":{"get":{"tags":["Analytics"],"summary":"Conversation sentiment analytics","responses":{"200":{"description":"Sentimento agregado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/analytics/agents-performance":{"get":{"tags":["Analytics"],"summary":"Agent performance metrics","responses":{"200":{"description":"Performance por agente","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/analytics/lead-score/{contactId}":{"get":{"tags":["Analytics"],"summary":"Lead score for contact","parameters":[{"name":"contactId","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Score e fatores","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/analytics/conversation-analysis/{id}":{"get":{"tags":["Analytics"],"summary":"Conversation analysis (sentiment, intent, summary)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Análise","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}}}}