{
  "openapi": "3.1.0",
  "info": {
    "title": "umbotao API",
    "version": "1.1.0",
    "description": "API gratuita. Gere a primeira chave em API → Gerar chave no painel. Envie Authorization: Bearer SEU_TOKEN. Chaves ficam restritas ao workspace e podem gerenciar outras chaves. Revogação imediata; sem expiração automática."
  },
  "servers": [
    {
      "url": "https://umbotao.com.br"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      },
      "sessionCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "lf_session",
        "description": "Sessão do painel. Escritas exigem Origin do site. Use Bearer nas integrações."
      }
    },
    "schemas": {
      "ProjectInput": {
        "type": "object",
        "required": [
          "name",
          "slug"
        ],
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 100
          },
          "slug": {
            "type": "string",
            "minLength": 3,
            "maxLength": 80,
            "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
          },
          "description": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "active": {
            "type": "boolean"
          },
          "captureEnabled": {
            "type": "boolean"
          },
          "captureFields": {
            "type": "array",
            "items": {
              "enum": [
                "name",
                "phone",
                "email"
              ]
            },
            "minItems": 1
          },
          "metaPixel": {
            "type": "string"
          },
          "googleAnalytics": {
            "type": "string"
          },
          "googleAds": {
            "type": "string"
          },
          "captureDesign": {
            "$ref": "#/components/schemas/CaptureDesign"
          },
          "ipTrackingEnabled": {
            "type": "boolean",
            "default": false,
            "description": "Opt-in IP-derived visitor estimates and country. Disabled by default; affects new events."
          }
        }
      },
      "DestinationInput": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "whatsapp": {
            "type": "string"
          },
          "active": {
            "type": "boolean"
          },
          "weight": {
            "type": "integer",
            "minimum": 1
          },
          "dailyLimit": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1
          },
          "notes": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "whatsapp",
              "external"
            ],
            "default": "whatsapp"
          },
          "url": {
            "type": "string",
            "description": "Obrigatório para type=external. URL HTTP/HTTPS completa, sem credenciais."
          }
        },
        "description": "WhatsApp (padrão): phone e whatsapp obrigatórios. Link externo: type=external e url obrigatórios; telefone dispensado."
      },
      "WebhookInput": {
        "type": "object",
        "required": [
          "url",
          "secret"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri"
          },
          "secret": {
            "type": "string",
            "minLength": 16
          }
        }
      },
      "ProjectPatch": {
        "type": "object",
        "required": [],
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 100
          },
          "slug": {
            "type": "string",
            "minLength": 3,
            "maxLength": 80,
            "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
          },
          "description": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "active": {
            "type": "boolean"
          },
          "captureEnabled": {
            "type": "boolean"
          },
          "captureFields": {
            "type": "array",
            "items": {
              "enum": [
                "name",
                "phone",
                "email"
              ]
            },
            "minItems": 1
          },
          "metaPixel": {
            "type": "string"
          },
          "googleAnalytics": {
            "type": "string"
          },
          "googleAds": {
            "type": "string"
          },
          "captureDesign": {
            "$ref": "#/components/schemas/CaptureDesign"
          },
          "ipTrackingEnabled": {
            "type": "boolean",
            "default": false,
            "description": "Opt-in IP-derived visitor estimates and country. Disabled by default; affects new events."
          }
        }
      },
      "DestinationPatch": {
        "type": "object",
        "required": [],
        "properties": {
          "name": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "whatsapp": {
            "type": "string"
          },
          "active": {
            "type": "boolean"
          },
          "weight": {
            "type": "integer",
            "minimum": 1
          },
          "dailyLimit": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1
          },
          "notes": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "whatsapp",
              "external"
            ],
            "default": "whatsapp"
          },
          "url": {
            "type": "string",
            "description": "Obrigatório para type=external. URL HTTP/HTTPS completa, sem credenciais."
          }
        },
        "description": "WhatsApp (padrão): phone e whatsapp obrigatórios. Link externo: type=external e url obrigatórios; telefone dispensado."
      },
      "CaptureDesign": {
        "type": "object",
        "description": "Configuração de aparência. Ao enviar este objeto, propriedades omitidas recebem os padrões.",
        "properties": {
          "brand": {
            "type": "string",
            "maxLength": 100,
            "default": "umbotao"
          },
          "showBrand": {
            "type": "boolean",
            "default": true
          },
          "logoUrl": {
            "anyOf": [
              {
                "const": ""
              },
              {
                "type": "string",
                "format": "uri",
                "pattern": "^https://"
              }
            ],
            "default": ""
          },
          "backgroundImage": {
            "anyOf": [
              {
                "const": ""
              },
              {
                "type": "string",
                "format": "uri",
                "pattern": "^https://"
              }
            ],
            "default": ""
          },
          "title": {
            "type": "string",
            "maxLength": 200,
            "default": ""
          },
          "subtitle": {
            "type": "string",
            "maxLength": 2000,
            "default": ""
          },
          "notice": {
            "type": "string",
            "maxLength": 2000,
            "default": "Seus dados serão enviados à equipe de {{projeto}} para atender à sua solicitação."
          },
          "button": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "default": "Continuar para o atendimento ↗"
          },
          "nameLabel": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "default": "Nome"
          },
          "phoneLabel": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "default": "WhatsApp"
          },
          "emailLabel": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "default": "E-mail"
          },
          "namePlaceholder": {
            "type": "string",
            "maxLength": 200,
            "default": ""
          },
          "phonePlaceholder": {
            "type": "string",
            "maxLength": 200,
            "default": "Ex.: +55 11 99999-9999"
          },
          "emailPlaceholder": {
            "type": "string",
            "maxLength": 200,
            "default": ""
          },
          "background": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$",
            "default": "#f7f8fa"
          },
          "card": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$",
            "default": "#f7f8fa"
          },
          "titleColor": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$",
            "default": "#202d2a"
          },
          "text": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$",
            "default": "#78837f"
          },
          "label": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$",
            "default": "#58665f"
          },
          "inputBackground": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$",
            "default": "#ffffff"
          },
          "inputText": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$",
            "default": "#202d2a"
          },
          "border": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$",
            "default": "#dde5e1"
          },
          "buttonColor": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$",
            "default": "#146c50"
          },
          "buttonText": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$",
            "default": "#ffffff"
          },
          "font": {
            "type": "string",
            "enum": [
              "sans",
              "serif",
              "mono"
            ],
            "default": "sans"
          },
          "alignment": {
            "type": "string",
            "enum": [
              "left",
              "center"
            ],
            "default": "left"
          },
          "radius": {
            "type": "integer",
            "minimum": 0,
            "maximum": 48,
            "default": 12
          },
          "width": {
            "type": "integer",
            "minimum": 320,
            "maximum": 1000,
            "default": 540
          },
          "padding": {
            "type": "integer",
            "minimum": 16,
            "maximum": 80,
            "default": 32
          },
          "fontSize": {
            "type": "integer",
            "minimum": 14,
            "maximum": 24,
            "default": 16
          },
          "shadow": {
            "type": "boolean",
            "default": false
          },
          "allowSkip": {
            "type": "boolean",
            "default": false,
            "description": "Allow a separate button to continue to WhatsApp without saving lead data."
          },
          "skipButton": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "default": "Ir para o WhatsApp sem preencher"
          }
        }
      }
    }
  },
  "paths": {
    "/api/projects": {
      "get": {
        "summary": "Listar projetos",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        }
      },
      "post": {
        "summary": "Criar projeto",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProjectInput"
              }
            }
          }
        }
      }
    },
    "/api/projects/{id}": {
      "get": {
        "summary": "Gerenciar projeto",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        }
      },
      "patch": {
        "summary": "Gerenciar projeto",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProjectPatch"
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Gerenciar projeto",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        }
      }
    },
    "/api/projects/{id}/destinations": {
      "get": {
        "summary": "Atendentes",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        }
      },
      "post": {
        "summary": "Atendentes",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DestinationInput"
              }
            }
          }
        }
      }
    },
    "/api/projects/{id}/destinations/{destinationId}": {
      "patch": {
        "summary": "Gerenciar atendente",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "destinationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DestinationPatch"
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Gerenciar atendente",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "destinationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        }
      }
    },
    "/api/analytics": {
      "get": {
        "summary": "analytics",
        "parameters": [
          {
            "name": "projectId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        }
      }
    },
    "/api/leads": {
      "get": {
        "summary": "leads",
        "parameters": [
          {
            "name": "projectId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        }
      }
    },
    "/api/distributions": {
      "get": {
        "summary": "distributions",
        "parameters": [
          {
            "name": "projectId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "format",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        }
      }
    },
    "/api/events": {
      "get": {
        "summary": "events",
        "parameters": [
          {
            "name": "projectId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "format",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        }
      }
    },
    "/api/projects/{id}/duplicate": {
      "post": {
        "summary": "duplicate",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        }
      }
    },
    "/api/projects/{id}/reorder": {
      "post": {
        "summary": "reorder",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "ids"
                ],
                "properties": {
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/projects/{id}/qr": {
      "get": {
        "summary": "qr",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        }
      }
    },
    "/api/webhooks": {
      "get": {
        "summary": "Webhooks",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        }
      },
      "post": {
        "summary": "Webhooks",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookInput"
              }
            }
          }
        }
      }
    },
    "/api/webhooks/{id}": {
      "delete": {
        "summary": "Excluir webhook",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        }
      }
    },
    "/api/keys": {
      "get": {
        "summary": "API Keys",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        },
        "security": [
          {
            "bearerAuth": []
          },
          {
            "sessionCookie": []
          }
        ],
        "description": "Lista metadados e prefixos; não retorna token completo nem hash."
      },
      "post": {
        "summary": "API Keys",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Token completo, retornado somente na criação.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "id",
                    "token"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "token": {
                      "type": "string",
                      "pattern": "^lf_[a-f0-9]{64}$"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/keys/{id}": {
      "delete": {
        "summary": "Revogar chave",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "201": {
            "description": "Criado"
          },
          "400": {
            "description": "Validação"
          },
          "401": {
            "description": "Não autenticado"
          },
          "403": {
            "description": "Acesso insuficiente"
          },
          "404": {
            "description": "Não encontrado"
          },
          "409": {
            "description": "Duplicado"
          },
          "429": {
            "description": "Limite atingido"
          }
        },
        "security": [
          {
            "bearerAuth": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/dashboard": {
      "get": {
        "summary": "Resumo do workspace",
        "responses": {
          "200": {
            "description": "Métricas resumidas"
          },
          "401": {
            "description": "Não autenticado"
          }
        }
      }
    },
    "/api/attendances": {
      "post": {
        "summary": "Confirmar um atendimento pela referência individual",
        "description": "Idempotente por referência. Usa token da mesma conta do projeto. Não aceita código MSG no lugar da referência UB. recorded é true somente na primeira confirmação.",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "sessionCookie": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reference"
                ],
                "properties": {
                  "reference": {
                    "type": "string",
                    "pattern": "^UB-[A-F0-9]{24}$",
                    "example": "UB-0123456789ABCDEF01234567"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Atendimento confirmado ou já registrado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "recorded": {
                      "type": "boolean"
                    },
                    "reference": {
                      "type": "string",
                      "pattern": "^UB-[A-F0-9]{24}$",
                      "example": "UB-0123456789ABCDEF01234567"
                    },
                    "messageCode": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Formato inválido"
          },
          "401": {
            "description": "Não autenticado"
          },
          "404": {
            "description": "Referência não existe nesta conta"
          },
          "429": {
            "description": "Limite de requisições"
          }
        }
      }
    },
    "/api/projects/{id}/messages": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "Listar variações e retorno confirmado",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "enum": [
                7,
                30,
                90
              ],
              "default": 30
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Taxa por coorte de cliques, incluindo confirmações posteriores",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "code",
                          "text",
                          "active"
                        ],
                        "properties": {
                          "code": {
                            "type": "string"
                          },
                          "text": {
                            "type": "string"
                          },
                          "active": {
                            "type": "boolean"
                          }
                        }
                      }
                    },
                    "days": {
                      "type": "integer"
                    },
                    "rows": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "code": {
                            "type": "string"
                          },
                          "text": {
                            "type": "string"
                          },
                          "redirects": {
                            "type": "integer"
                          },
                          "attended": {
                            "type": "integer"
                          },
                          "rate": {
                            "type": "number"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Projeto não encontrado"
          }
        }
      },
      "post": {
        "summary": "Adicionar ou pausar/reativar uma variação",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "sessionCookie": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "type": "object",
                    "required": [
                      "action",
                      "text"
                    ],
                    "properties": {
                      "action": {
                        "type": "string",
                        "enum": [
                          "add"
                        ]
                      },
                      "text": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 1800
                      }
                    }
                  },
                  {
                    "type": "object",
                    "required": [
                      "action",
                      "code",
                      "active"
                    ],
                    "properties": {
                      "action": {
                        "type": "string",
                        "enum": [
                          "toggle"
                        ]
                      },
                      "code": {
                        "type": "string"
                      },
                      "active": {
                        "type": "boolean"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Variações atualizadas",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "code",
                          "text",
                          "active"
                        ],
                        "properties": {
                          "code": {
                            "type": "string"
                          },
                          "text": {
                            "type": "string"
                          },
                          "active": {
                            "type": "boolean"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Entrada inválida, limite de 30 versões ou tentativa de pausar a última mensagem"
          },
          "404": {
            "description": "Projeto ou código não encontrado"
          }
        }
      }
    }
  }
}
