openapi: 3.1.0 info: title: Api version: 1.0.0 description: WhatsApp SaaS Multi-Tenant Platform API servers: - url: /api description: Base API path tags: - name: health description: Health operations - name: auth description: Authentication - name: admin description: Admin panel operations - name: reseller description: Reseller panel operations - name: merchant description: Merchant panel operations - name: plans description: Plans and features - name: subscriptions description: Subscriptions management - name: billing description: Billing and payments (Asaas) - name: commissions description: Reseller commissions - name: conversations description: WhatsApp conversations - name: contacts description: CRM contacts - name: appointments description: Agenda / scheduling - name: campaigns description: Marketing campaigns - name: radar description: Radar de oportunidades / leads - name: erp description: ERP interno - name: reports description: Reports and analytics - name: ai description: AI settings and usage - name: team description: Team management - name: webhooks description: Webhook management paths: /healthz: get: operationId: healthCheck tags: [health] summary: Health check responses: "200": description: Healthy content: application/json: schema: $ref: "#/components/schemas/HealthStatus" # ==================== AUTH ==================== /auth/login: post: operationId: login tags: [auth] summary: Login requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/LoginRequest" responses: "200": description: Login successful content: application/json: schema: $ref: "#/components/schemas/AuthResponse" "401": description: Invalid credentials content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /auth/logout: post: operationId: logout tags: [auth] summary: Logout responses: "200": description: Logged out content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /auth/me: get: operationId: getMe tags: [auth] summary: Get current user responses: "200": description: Current user content: application/json: schema: $ref: "#/components/schemas/UserProfile" /auth/refresh: post: operationId: refreshToken tags: [auth] summary: Refresh access token responses: "200": description: Token refreshed content: application/json: schema: $ref: "#/components/schemas/AuthResponse" /auth/register/merchant: post: operationId: registerMerchant tags: [auth] summary: Register as merchant (with optional reseller referral) requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/RegisterMerchantRequest" responses: "201": description: Merchant registered content: application/json: schema: $ref: "#/components/schemas/AuthResponse" # ==================== PLANS ==================== /plans: get: operationId: listPlans tags: [plans] summary: List all plans responses: "200": description: List of plans content: application/json: schema: type: array items: $ref: "#/components/schemas/Plan" post: operationId: createPlan tags: [plans] summary: Create a plan (admin only) requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreatePlanRequest" responses: "201": description: Plan created content: application/json: schema: $ref: "#/components/schemas/Plan" /plans/{id}: get: operationId: getPlan tags: [plans] summary: Get plan by ID parameters: - name: id in: path required: true schema: type: string responses: "200": description: Plan details content: application/json: schema: $ref: "#/components/schemas/Plan" put: operationId: updatePlan tags: [plans] summary: Update a plan (admin only) parameters: - name: id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreatePlanRequest" responses: "200": description: Plan updated content: application/json: schema: $ref: "#/components/schemas/Plan" # ==================== ADMIN ==================== /admin/dashboard: get: operationId: getAdminDashboard tags: [admin] summary: Admin dashboard stats responses: "200": description: Dashboard statistics content: application/json: schema: $ref: "#/components/schemas/AdminDashboardStats" /admin/resellers: get: operationId: listResellers tags: [admin] summary: List all resellers parameters: - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 20 - name: search in: query schema: type: string responses: "200": description: Resellers list content: application/json: schema: $ref: "#/components/schemas/PaginatedResellers" post: operationId: createReseller tags: [admin] summary: Create a reseller requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreateResellerRequest" responses: "201": description: Reseller created content: application/json: schema: $ref: "#/components/schemas/Reseller" /admin/resellers/{id}: get: operationId: getReseller tags: [admin] summary: Get reseller by ID parameters: - name: id in: path required: true schema: type: string responses: "200": description: Reseller details content: application/json: schema: $ref: "#/components/schemas/Reseller" put: operationId: updateReseller tags: [admin] summary: Update reseller parameters: - name: id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/UpdateResellerRequest" responses: "200": description: Reseller updated content: application/json: schema: $ref: "#/components/schemas/Reseller" /admin/resellers/{id}/status: put: operationId: updateResellerStatus tags: [admin] summary: Block/suspend/activate reseller parameters: - name: id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/UpdateStatusRequest" responses: "200": description: Status updated content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /admin/merchants: get: operationId: listAllMerchants tags: [admin] summary: List all merchants parameters: - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 20 - name: search in: query schema: type: string - name: resellerId in: query schema: type: string - name: status in: query schema: type: string responses: "200": description: Merchants list content: application/json: schema: $ref: "#/components/schemas/PaginatedMerchants" /admin/merchants/{id}/status: put: operationId: updateMerchantStatus tags: [admin] summary: Block/suspend/activate merchant parameters: - name: id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/UpdateStatusRequest" responses: "200": description: Status updated content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /admin/subscriptions: get: operationId: listAllSubscriptions tags: [admin] summary: List all subscriptions parameters: - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 20 - name: status in: query schema: type: string responses: "200": description: Subscriptions list content: application/json: schema: $ref: "#/components/schemas/PaginatedSubscriptions" /admin/commissions: get: operationId: listAllCommissions tags: [admin] summary: List all commissions parameters: - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 20 - name: resellerId in: query schema: type: string responses: "200": description: Commissions list content: application/json: schema: $ref: "#/components/schemas/PaginatedCommissions" /admin/billing/asaas-config: get: operationId: getAsaasConfig tags: [admin] summary: Get Asaas integration configuration and webhook URLs responses: "200": description: Asaas config with webhook URLs content: application/json: schema: $ref: "#/components/schemas/AsaasConfig" put: operationId: updateAsaasConfig tags: [admin] summary: Update Asaas API key configuration requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/UpdateAsaasConfigRequest" responses: "200": description: Config updated content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /admin/billing/nfse-config: get: operationId: getNfseConfig tags: [admin] summary: Get NFS-e (Nota Fiscal) configuration responses: "200": description: NFS-e configuration content: application/json: schema: $ref: "#/components/schemas/NfseConfig" put: operationId: updateNfseConfig tags: [admin] summary: Update NFS-e configuration requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/NfseConfig" responses: "200": description: NFS-e config updated content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /admin/ai-usage: get: operationId: getAdminAiUsage tags: [admin] summary: Get AI usage across all merchants parameters: - name: period in: query schema: type: string enum: [today, week, month] default: month responses: "200": description: AI usage stats content: application/json: schema: $ref: "#/components/schemas/AiUsageStats" /admin/audit-logs: get: operationId: listAuditLogs tags: [admin] summary: List audit logs parameters: - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 50 - name: userId in: query schema: type: string - name: action in: query schema: type: string responses: "200": description: Audit logs content: application/json: schema: $ref: "#/components/schemas/PaginatedAuditLogs" /admin/webhooks: get: operationId: listWebhooks tags: [admin] summary: List configured webhooks responses: "200": description: Webhooks list content: application/json: schema: type: array items: $ref: "#/components/schemas/Webhook" # ==================== RESELLER ==================== /reseller/dashboard: get: operationId: getResellerDashboard tags: [reseller] summary: Reseller dashboard stats responses: "200": description: Dashboard stats content: application/json: schema: $ref: "#/components/schemas/ResellerDashboardStats" /reseller/merchants: get: operationId: listResellerMerchants tags: [reseller] summary: List reseller's merchants parameters: - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 20 - name: search in: query schema: type: string - name: status in: query schema: type: string responses: "200": description: Merchants list content: application/json: schema: $ref: "#/components/schemas/PaginatedMerchants" post: operationId: createResellerMerchant tags: [reseller] summary: Create a merchant under this reseller requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreateMerchantRequest" responses: "201": description: Merchant created content: application/json: schema: $ref: "#/components/schemas/Merchant" /reseller/commissions: get: operationId: listResellerCommissions tags: [reseller] summary: List reseller commissions parameters: - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 20 - name: period in: query schema: type: string enum: [today, week, month, year] default: month responses: "200": description: Commissions content: application/json: schema: $ref: "#/components/schemas/ResellerCommissionsSummary" /reseller/commission-tiers: get: operationId: getCommissionTiers tags: [reseller] summary: Get progressive commission tier structure responses: "200": description: Commission tiers content: application/json: schema: $ref: "#/components/schemas/CommissionTiers" /reseller/referral-link: get: operationId: getResellerReferralLink tags: [reseller] summary: Get reseller's referral link responses: "200": description: Referral link content: application/json: schema: $ref: "#/components/schemas/ReferralLink" /reseller/subscriptions: get: operationId: listResellerSubscriptions tags: [reseller] summary: List subscriptions of reseller's merchants parameters: - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 20 responses: "200": description: Subscriptions content: application/json: schema: $ref: "#/components/schemas/PaginatedSubscriptions" # ==================== MERCHANT DASHBOARD ==================== /merchant/dashboard: get: operationId: getMerchantDashboard tags: [merchant] summary: Merchant dashboard stats responses: "200": description: Dashboard stats content: application/json: schema: $ref: "#/components/schemas/MerchantDashboardStats" # ==================== CONVERSATIONS ==================== /conversations: get: operationId: listConversations tags: [conversations] summary: List conversations (WhatsApp live chat) parameters: - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 20 - name: status in: query schema: type: string enum: [open, resolved, pending, bot] - name: search in: query schema: type: string - name: assignedTo in: query schema: type: string responses: "200": description: Conversations list content: application/json: schema: $ref: "#/components/schemas/PaginatedConversations" /conversations/{id}: get: operationId: getConversation tags: [conversations] summary: Get conversation with messages parameters: - name: id in: path required: true schema: type: string responses: "200": description: Conversation with messages content: application/json: schema: $ref: "#/components/schemas/ConversationDetail" /conversations/{id}/messages: post: operationId: sendMessage tags: [conversations] summary: Send a message in a conversation parameters: - name: id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/SendMessageRequest" responses: "201": description: Message sent content: application/json: schema: $ref: "#/components/schemas/Message" /conversations/{id}/assign: post: operationId: assignConversation tags: [conversations] summary: Assign conversation to agent parameters: - name: id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/AssignRequest" responses: "200": description: Assigned content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /conversations/{id}/status: put: operationId: updateConversationStatus tags: [conversations] summary: Update conversation status (resolve, reopen, etc.) parameters: - name: id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/UpdateConversationStatusRequest" responses: "200": description: Status updated content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /conversations/{id}/toggle-bot: post: operationId: toggleConversationBot tags: [conversations] summary: Enable/disable AI bot for conversation parameters: - name: id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: type: object properties: enabled: type: boolean required: [enabled] responses: "200": description: Bot toggled content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" # ==================== CONTACTS / CRM ==================== /contacts: get: operationId: listContacts tags: [contacts] summary: List CRM contacts parameters: - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 20 - name: search in: query schema: type: string - name: tag in: query schema: type: string - name: status in: query schema: type: string responses: "200": description: Contacts content: application/json: schema: $ref: "#/components/schemas/PaginatedContacts" post: operationId: createContact tags: [contacts] summary: Create a contact requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreateContactRequest" responses: "201": description: Contact created content: application/json: schema: $ref: "#/components/schemas/Contact" /contacts/{id}: get: operationId: getContact tags: [contacts] summary: Get contact details parameters: - name: id in: path required: true schema: type: string responses: "200": description: Contact details content: application/json: schema: $ref: "#/components/schemas/ContactDetail" put: operationId: updateContact tags: [contacts] summary: Update a contact parameters: - name: id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreateContactRequest" responses: "200": description: Contact updated content: application/json: schema: $ref: "#/components/schemas/Contact" delete: operationId: deleteContact tags: [contacts] summary: Delete a contact parameters: - name: id in: path required: true schema: type: string responses: "200": description: Deleted content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" # ==================== APPOINTMENTS ==================== /appointments: get: operationId: listAppointments tags: [appointments] summary: List appointments parameters: - name: start in: query schema: type: string format: date - name: end in: query schema: type: string format: date - name: status in: query schema: type: string responses: "200": description: Appointments content: application/json: schema: type: array items: $ref: "#/components/schemas/Appointment" post: operationId: createAppointment tags: [appointments] summary: Create appointment requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreateAppointmentRequest" responses: "201": description: Appointment created content: application/json: schema: $ref: "#/components/schemas/Appointment" /appointments/{id}: put: operationId: updateAppointment tags: [appointments] summary: Update appointment parameters: - name: id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreateAppointmentRequest" responses: "200": description: Appointment updated content: application/json: schema: $ref: "#/components/schemas/Appointment" delete: operationId: deleteAppointment tags: [appointments] summary: Cancel appointment parameters: - name: id in: path required: true schema: type: string responses: "200": description: Cancelled content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" # ==================== CAMPAIGNS ==================== /campaigns: get: operationId: listCampaigns tags: [campaigns] summary: List campaigns parameters: - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 20 - name: status in: query schema: type: string responses: "200": description: Campaigns content: application/json: schema: $ref: "#/components/schemas/PaginatedCampaigns" post: operationId: createCampaign tags: [campaigns] summary: Create a campaign requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreateCampaignRequest" responses: "201": description: Campaign created content: application/json: schema: $ref: "#/components/schemas/Campaign" /campaigns/{id}: get: operationId: getCampaign tags: [campaigns] summary: Get campaign details parameters: - name: id in: path required: true schema: type: string responses: "200": description: Campaign details content: application/json: schema: $ref: "#/components/schemas/Campaign" put: operationId: updateCampaign tags: [campaigns] summary: Update campaign parameters: - name: id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreateCampaignRequest" responses: "200": description: Campaign updated content: application/json: schema: $ref: "#/components/schemas/Campaign" delete: operationId: deleteCampaign tags: [campaigns] summary: Delete campaign parameters: - name: id in: path required: true schema: type: string responses: "200": description: Deleted content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /campaigns/{id}/send: post: operationId: sendCampaign tags: [campaigns] summary: Send campaign now parameters: - name: id in: path required: true schema: type: string responses: "200": description: Campaign sent content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" # ==================== RADAR ==================== /radar/search: post: operationId: startRadarSearch tags: [radar] summary: Start radar lead search requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/RadarSearchRequest" responses: "201": description: Search started content: application/json: schema: $ref: "#/components/schemas/RadarSearch" /radar/leads: get: operationId: listRadarLeads tags: [radar] summary: List radar leads parameters: - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 20 - name: searchId in: query schema: type: string - name: status in: query schema: type: string responses: "200": description: Leads list content: application/json: schema: $ref: "#/components/schemas/PaginatedRadarLeads" /radar/leads/{id}/generate-approach: post: operationId: generateLeadApproach tags: [radar] summary: Generate AI approach for lead parameters: - name: id in: path required: true schema: type: string responses: "200": description: Approach generated content: application/json: schema: $ref: "#/components/schemas/LeadApproach" /radar/leads/{id}/add-crm: post: operationId: addLeadToCrm tags: [radar] summary: Add radar lead to CRM parameters: - name: id in: path required: true schema: type: string responses: "200": description: Lead added to CRM content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" # ==================== ERP ==================== /erp/finance: get: operationId: getErpFinance tags: [erp] summary: Get ERP finance data parameters: - name: period in: query schema: type: string enum: [today, week, month, year] default: month responses: "200": description: Finance data content: application/json: schema: $ref: "#/components/schemas/ErpFinanceData" /erp/sales: get: operationId: getErpSales tags: [erp] summary: Get ERP sales data parameters: - name: period in: query schema: type: string enum: [today, week, month, year] default: month responses: "200": description: Sales data content: application/json: schema: $ref: "#/components/schemas/ErpSalesData" /erp/tasks: get: operationId: listErpTasks tags: [erp] summary: List ERP tasks parameters: - name: status in: query schema: type: string enum: [pending, in_progress, done] responses: "200": description: Tasks content: application/json: schema: type: array items: $ref: "#/components/schemas/Task" post: operationId: createErpTask tags: [erp] summary: Create task requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreateTaskRequest" responses: "201": description: Task created content: application/json: schema: $ref: "#/components/schemas/Task" # ==================== REPORTS ==================== /reports/sales: get: operationId: getSalesReport tags: [reports] summary: Get sales report parameters: - name: period in: query schema: type: string enum: [today, week, month, year] default: month responses: "200": description: Sales report content: application/json: schema: $ref: "#/components/schemas/SalesReport" /reports/conversations: get: operationId: getConversationsReport tags: [reports] summary: Get conversations report parameters: - name: period in: query schema: type: string enum: [today, week, month, year] default: month responses: "200": description: Conversations report content: application/json: schema: $ref: "#/components/schemas/ConversationsReport" # ==================== AI ==================== /ai/usage: get: operationId: getAiUsage tags: [ai] summary: Get merchant AI usage parameters: - name: period in: query schema: type: string enum: [today, week, month] default: month responses: "200": description: AI usage content: application/json: schema: $ref: "#/components/schemas/MerchantAiUsage" /ai/settings: get: operationId: getAiSettings tags: [ai] summary: Get AI configuration responses: "200": description: AI settings content: application/json: schema: $ref: "#/components/schemas/AiSettings" put: operationId: updateAiSettings tags: [ai] summary: Update AI settings requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/UpdateAiSettingsRequest" responses: "200": description: Settings updated content: application/json: schema: $ref: "#/components/schemas/AiSettings" /ai/autopilot: get: operationId: getAutopilotSettings tags: [ai] summary: Get autopilot settings responses: "200": description: Autopilot settings content: application/json: schema: $ref: "#/components/schemas/AutopilotSettings" put: operationId: updateAutopilotSettings tags: [ai] summary: Update autopilot settings requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/AutopilotSettings" responses: "200": description: Settings updated content: application/json: schema: $ref: "#/components/schemas/AutopilotSettings" # ==================== TEAM ==================== /team: get: operationId: listTeamMembers tags: [team] summary: List team members responses: "200": description: Team members content: application/json: schema: type: array items: $ref: "#/components/schemas/TeamMember" post: operationId: inviteTeamMember tags: [team] summary: Invite a team member requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/InviteTeamMemberRequest" responses: "201": description: Invite sent content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" # ==================== BILLING WEBHOOKS (Asaas) ==================== /webhooks/asaas: post: operationId: asaasWebhook tags: [webhooks] summary: Asaas payment webhook (register this URL in Asaas) requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/AsaasWebhookEvent" responses: "200": description: Webhook processed content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /webhooks/whatsapp/evolution: post: operationId: evolutionWebhook tags: [webhooks] summary: Evolution API webhook for WhatsApp messages (register this URL in Evolution) requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/EvolutionWebhookEvent" responses: "200": description: Webhook processed content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" # ==================== MERCHANT BILLING ==================== /merchant/subscription: get: operationId: getMerchantSubscription tags: [merchant] summary: Get merchant's current subscription responses: "200": description: Subscription info content: application/json: schema: $ref: "#/components/schemas/MerchantSubscription" /merchant/subscription/upgrade: post: operationId: upgradeMerchantSubscription tags: [merchant] summary: Upgrade subscription plan requestBody: required: true content: application/json: schema: type: object properties: planId: type: string required: [planId] responses: "200": description: Upgrade initiated content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /merchant/invoices: get: operationId: listMerchantInvoices tags: [merchant] summary: List merchant invoices responses: "200": description: Invoices content: application/json: schema: type: array items: $ref: "#/components/schemas/Invoice" components: schemas: HealthStatus: type: object properties: status: type: string required: [status] ErrorResponse: type: object properties: error: type: string message: type: string required: [error, message] SuccessResponse: type: object properties: success: type: boolean message: type: string required: [success] LoginRequest: type: object properties: email: type: string format: email password: type: string minLength: 6 required: [email, password] AuthResponse: type: object properties: token: type: string user: $ref: "#/components/schemas/UserProfile" required: [token, user] UserProfile: type: object properties: id: type: string email: type: string name: type: string role: type: string enum: [ADMIN, RESELLER, MERCHANT_OWNER, MERCHANT_MANAGER, MERCHANT_AGENT, MERCHANT_FINANCE, MERCHANT_VIEWER] merchantId: type: string nullable: true resellerId: type: string nullable: true avatarUrl: type: string nullable: true createdAt: type: string format: date-time required: [id, email, name, role, createdAt] RegisterMerchantRequest: type: object properties: name: type: string email: type: string format: email password: type: string minLength: 6 phone: type: string businessName: type: string planId: type: string referralCode: type: string nullable: true required: [name, email, password, phone, businessName, planId] Plan: type: object properties: id: type: string name: type: string description: type: string price: type: number currency: type: string default: BRL billingCycle: type: string enum: [monthly, yearly] trialDays: type: integer maxContacts: type: integer maxCampaigns: type: integer maxAgents: type: integer maxAiTokensPerMonth: type: integer features: type: array items: $ref: "#/components/schemas/PlanFeature" isActive: type: boolean createdAt: type: string format: date-time required: [id, name, price, billingCycle, features, isActive, createdAt] PlanFeature: type: object properties: module: type: string enum: - IA_ATENDENTE - IA_VENDEDOR - IA_AGENDA - IA_SENSE - IA_REATIVADOR - IA_ERP_INTERNO - IA_FINANCEIRO - IA_RELATORIOS - IA_RADAR_LEADS - CONVERSATIONS - CRM - AGENDA - CAMPAIGNS - RADAR_OPORTUNIDADES - ERP_INTERNO - REPORTS - ANALYTICS - KNOWLEDGE_BASE - APPROVALS - WHATSAPP_MULTI_DEVICE enabled: type: boolean limit: type: integer nullable: true required: [module, enabled] CreatePlanRequest: type: object properties: name: type: string description: type: string price: type: number billingCycle: type: string enum: [monthly, yearly] trialDays: type: integer default: 7 maxContacts: type: integer maxCampaigns: type: integer maxAgents: type: integer maxAiTokensPerMonth: type: integer features: type: array items: $ref: "#/components/schemas/PlanFeature" isActive: type: boolean default: true required: [name, price, billingCycle, features] Reseller: type: object properties: id: type: string name: type: string email: type: string phone: type: string company: type: string status: type: string enum: [active, suspended, blocked] referralCode: type: string merchantCount: type: integer totalRevenue: type: number currentTierCommission: type: number minimumSales: type: number createdAt: type: string format: date-time required: [id, name, email, status, referralCode, createdAt] CreateResellerRequest: type: object properties: name: type: string email: type: string format: email password: type: string minLength: 6 phone: type: string company: type: string minimumSales: type: number description: Minimum monthly sales amount to earn base commission baseCommissionPercent: type: number description: Base commission percentage (e.g. 10 for 10%) required: [name, email, password, phone, baseCommissionPercent] UpdateResellerRequest: type: object properties: name: type: string phone: type: string company: type: string minimumSales: type: number baseCommissionPercent: type: number UpdateStatusRequest: type: object properties: status: type: string enum: [active, suspended, blocked] reason: type: string required: [status] Merchant: type: object properties: id: type: string businessName: type: string ownerName: type: string email: type: string phone: type: string status: type: string enum: [active, suspended, blocked, trial, overdue, grace_period, cancelled] resellerId: type: string nullable: true planId: type: string planName: type: string subscriptionStatus: type: string whatsappConnected: type: boolean createdAt: type: string format: date-time required: [id, businessName, email, status, createdAt] CreateMerchantRequest: type: object properties: businessName: type: string ownerName: type: string email: type: string format: email password: type: string minLength: 6 phone: type: string planId: type: string required: [businessName, ownerName, email, password, phone, planId] PaginatedResellers: type: object properties: data: type: array items: $ref: "#/components/schemas/Reseller" total: type: integer page: type: integer limit: type: integer totalPages: type: integer required: [data, total, page, limit, totalPages] PaginatedMerchants: type: object properties: data: type: array items: $ref: "#/components/schemas/Merchant" total: type: integer page: type: integer limit: type: integer totalPages: type: integer required: [data, total, page, limit, totalPages] PaginatedSubscriptions: type: object properties: data: type: array items: $ref: "#/components/schemas/Subscription" total: type: integer page: type: integer limit: type: integer totalPages: type: integer required: [data, total, page, limit, totalPages] PaginatedCommissions: type: object properties: data: type: array items: $ref: "#/components/schemas/Commission" total: type: integer page: type: integer limit: type: integer totalPages: type: integer required: [data, total, page, limit, totalPages] Subscription: type: object properties: id: type: string merchantId: type: string merchantName: type: string planId: type: string planName: type: string status: type: string enum: [trial, active, overdue, grace_period, final_notice, suspended, cancelled] asaasSubscriptionId: type: string nullable: true currentPeriodStart: type: string format: date-time currentPeriodEnd: type: string format: date-time trialEndsAt: type: string format: date-time nullable: true amount: type: number createdAt: type: string format: date-time required: [id, merchantId, planId, status, amount, createdAt] Commission: type: object properties: id: type: string resellerId: type: string resellerName: type: string merchantId: type: string merchantName: type: string amount: type: number percent: type: number tier: type: string status: type: string enum: [pending, paid, cancelled] periodMonth: type: integer periodYear: type: integer createdAt: type: string format: date-time required: [id, resellerId, merchantId, amount, percent, status, createdAt] AdminDashboardStats: type: object properties: totalResellers: type: integer activeResellers: type: integer totalMerchants: type: integer activeMerchants: type: integer mrr: type: number totalRevenue: type: number totalAiTokensUsed: type: integer activeSubscriptions: type: integer trialSubscriptions: type: integer overdueSubscriptions: type: integer recentSignups: type: array items: $ref: "#/components/schemas/Merchant" revenueChart: type: array items: $ref: "#/components/schemas/ChartDataPoint" required: [totalResellers, totalMerchants, mrr, totalRevenue, activeSubscriptions] ResellerDashboardStats: type: object properties: totalMerchants: type: integer activeMerchants: type: integer monthlyRevenue: type: number totalCommission: type: number pendingCommission: type: number currentTierPercent: type: number nextTierTarget: type: number nextTierPercent: type: number salesThisMonth: type: number minimumSales: type: number commissionChart: type: array items: $ref: "#/components/schemas/ChartDataPoint" required: [totalMerchants, monthlyRevenue, totalCommission, currentTierPercent] MerchantDashboardStats: type: object properties: conversationsToday: type: integer appointmentsToday: type: integer salesToday: type: number revenueThisMonth: type: number newContactsThisMonth: type: integer activeLeads: type: integer activeCampaigns: type: integer aiTokensUsed: type: integer aiTokensLimit: type: integer whatsappStatus: type: string enum: [connected, disconnected, qr_pending] subscriptionStatus: type: string openConversations: type: integer pendingApprovals: type: integer revenueChart: type: array items: $ref: "#/components/schemas/ChartDataPoint" conversationsChart: type: array items: $ref: "#/components/schemas/ChartDataPoint" required: [conversationsToday, appointmentsToday, salesToday, revenueThisMonth, whatsappStatus, subscriptionStatus] ChartDataPoint: type: object properties: label: type: string value: type: number date: type: string required: [label, value] AsaasConfig: type: object properties: apiKeyConfigured: type: boolean environment: type: string enum: [sandbox, production] webhookUrl: type: string description: Register this URL in Asaas dashboard as payment webhook subscriptionWebhookUrl: type: string description: Register this URL in Asaas for subscription events webhookToken: type: string description: Token to validate Asaas webhook requests asaasAccountId: type: string nullable: true required: [apiKeyConfigured, environment, webhookUrl, subscriptionWebhookUrl, webhookToken] UpdateAsaasConfigRequest: type: object properties: apiKey: type: string environment: type: string enum: [sandbox, production] required: [apiKey, environment] NfseConfig: type: object properties: enabled: type: boolean description: Master switch to enable/disable automated NFS-e generation municipalServiceCode: type: string description: Municipal code for the service provided serviceDescription: type: string description: Description of the service on the nota fiscal deductionAmount: type: number description: Deduction amount (in BRL) observations: type: string description: Additional observations on the nota fiscal issueOnPayment: type: boolean description: Automatically issue NFS-e when payment is confirmed required: [enabled, issueOnPayment] AiUsageStats: type: object properties: totalTokensUsed: type: integer totalCost: type: number byMerchant: type: array items: type: object properties: merchantId: type: string merchantName: type: string tokensUsed: type: integer limitPercent: type: number required: [merchantId, merchantName, tokensUsed, limitPercent] byAgent: type: array items: type: object properties: agentType: type: string tokensUsed: type: integer required: [agentType, tokensUsed] required: [totalTokensUsed, totalCost] MerchantAiUsage: type: object properties: tokensUsed: type: integer tokensLimit: type: integer percentUsed: type: number byAgent: type: array items: type: object properties: agentType: type: string enum: [IA_ATENDENTE, IA_VENDEDOR, IA_AGENDA, IA_SENSE, IA_REATIVADOR, IA_ERP_INTERNO, IA_FINANCEIRO, IA_RELATORIOS, IA_RADAR_LEADS] tokensUsed: type: integer callsCount: type: integer required: [agentType, tokensUsed, callsCount] usageChart: type: array items: $ref: "#/components/schemas/ChartDataPoint" required: [tokensUsed, tokensLimit, percentUsed] PaginatedAuditLogs: type: object properties: data: type: array items: $ref: "#/components/schemas/AuditLog" total: type: integer page: type: integer limit: type: integer totalPages: type: integer required: [data, total, page, limit, totalPages] AuditLog: type: object properties: id: type: string userId: type: string userEmail: type: string action: type: string resource: type: string resourceId: type: string nullable: true details: type: object nullable: true additionalProperties: true ip: type: string nullable: true createdAt: type: string format: date-time required: [id, userId, userEmail, action, resource, createdAt] Webhook: type: object properties: id: type: string name: type: string url: type: string events: type: array items: type: string isActive: type: boolean lastTriggeredAt: type: string format: date-time nullable: true required: [id, name, url, events, isActive] ResellerCommissionsSummary: type: object properties: totalEarned: type: number pendingPayout: type: number paidOut: type: number currentTier: type: string currentTierPercent: type: number salesThisMonth: type: number minimumSales: type: number aboveMinimum: type: boolean commissions: type: array items: $ref: "#/components/schemas/Commission" required: [totalEarned, pendingPayout, paidOut, currentTierPercent, salesThisMonth, aboveMinimum] CommissionTiers: type: object properties: minimumSales: type: number description: Minimum monthly sales to earn commission tiers: type: array items: type: object properties: minSales: type: number maxSales: type: number nullable: true commissionPercent: type: number label: type: string required: [minSales, commissionPercent, label] required: [minimumSales, tiers] ReferralLink: type: object properties: code: type: string url: type: string clicks: type: integer conversions: type: integer required: [code, url, clicks, conversions] Conversation: type: object properties: id: type: string contactId: type: string contactName: type: string contactPhone: type: string contactAvatarUrl: type: string nullable: true lastMessage: type: string nullable: true lastMessageAt: type: string format: date-time nullable: true status: type: string enum: [open, resolved, pending, bot] assignedTo: type: string nullable: true assignedAgentName: type: string nullable: true unreadCount: type: integer botEnabled: type: boolean tags: type: array items: type: string createdAt: type: string format: date-time required: [id, contactId, contactName, contactPhone, status, unreadCount, botEnabled, tags, createdAt] ConversationDetail: type: object properties: conversation: $ref: "#/components/schemas/Conversation" messages: type: array items: $ref: "#/components/schemas/Message" contact: $ref: "#/components/schemas/Contact" required: [conversation, messages, contact] Message: type: object properties: id: type: string conversationId: type: string content: type: string mediaUrl: type: string nullable: true mediaType: type: string nullable: true enum: [image, video, audio, document, null] direction: type: string enum: [inbound, outbound] sender: type: string enum: [customer, agent, bot] senderName: type: string nullable: true status: type: string enum: [sent, delivered, read, failed] createdAt: type: string format: date-time required: [id, conversationId, content, direction, sender, status, createdAt] SendMessageRequest: type: object properties: content: type: string mediaUrl: type: string nullable: true mediaType: type: string nullable: true required: [content] AssignRequest: type: object properties: agentId: type: string nullable: true required: [agentId] UpdateConversationStatusRequest: type: object properties: status: type: string enum: [open, resolved, pending] required: [status] PaginatedConversations: type: object properties: data: type: array items: $ref: "#/components/schemas/Conversation" total: type: integer page: type: integer limit: type: integer totalPages: type: integer required: [data, total, page, limit, totalPages] Contact: type: object properties: id: type: string name: type: string phone: type: string email: type: string nullable: true avatarUrl: type: string nullable: true tags: type: array items: type: string status: type: string enum: [lead, prospect, customer, inactive] lastConversationAt: type: string format: date-time nullable: true notes: type: string nullable: true createdAt: type: string format: date-time required: [id, name, phone, tags, status, createdAt] ContactDetail: type: object properties: contact: $ref: "#/components/schemas/Contact" recentConversations: type: array items: $ref: "#/components/schemas/Conversation" appointments: type: array items: $ref: "#/components/schemas/Appointment" required: [contact, recentConversations, appointments] CreateContactRequest: type: object properties: name: type: string phone: type: string email: type: string nullable: true tags: type: array items: type: string status: type: string enum: [lead, prospect, customer, inactive] notes: type: string nullable: true required: [name, phone] PaginatedContacts: type: object properties: data: type: array items: $ref: "#/components/schemas/Contact" total: type: integer page: type: integer limit: type: integer totalPages: type: integer required: [data, total, page, limit, totalPages] Appointment: type: object properties: id: type: string contactId: type: string contactName: type: string contactPhone: type: string title: type: string description: type: string nullable: true startAt: type: string format: date-time endAt: type: string format: date-time status: type: string enum: [scheduled, confirmed, cancelled, completed, no_show] assignedTo: type: string nullable: true createdAt: type: string format: date-time required: [id, contactId, contactName, contactPhone, title, startAt, endAt, status, createdAt] CreateAppointmentRequest: type: object properties: contactId: type: string title: type: string description: type: string nullable: true startAt: type: string format: date-time endAt: type: string format: date-time assignedTo: type: string nullable: true required: [contactId, title, startAt, endAt] Campaign: type: object properties: id: type: string name: type: string message: type: string status: type: string enum: [draft, scheduled, sending, sent, paused, cancelled] targetCount: type: integer sentCount: type: integer deliveredCount: type: integer readCount: type: integer responseCount: type: integer scheduledAt: type: string format: date-time nullable: true sentAt: type: string format: date-time nullable: true createdAt: type: string format: date-time required: [id, name, message, status, targetCount, sentCount, deliveredCount, readCount, responseCount, createdAt] CreateCampaignRequest: type: object properties: name: type: string message: type: string targetTags: type: array items: type: string targetStatus: type: array items: type: string scheduledAt: type: string format: date-time nullable: true required: [name, message] PaginatedCampaigns: type: object properties: data: type: array items: $ref: "#/components/schemas/Campaign" total: type: integer page: type: integer limit: type: integer totalPages: type: integer required: [data, total, page, limit, totalPages] RadarSearchRequest: type: object properties: niche: type: string city: type: string state: type: string companySize: type: string enum: [micro, small, medium, large] nullable: true filters: type: array items: type: string enum: [no_site, no_whatsapp, low_rating, new_company, has_bids] leadLimit: type: integer minimum: 1 maximum: 200 nullable: true description: Optional maximum number of leads to save. When set, the radar prioritizes the best-scored leads. required: [niche, city, state] RadarSearch: type: object properties: id: type: string niche: type: string city: type: string state: type: string status: type: string enum: [pending, searching, enriching, completed, failed] leadsFound: type: integer createdAt: type: string format: date-time required: [id, niche, city, state, status, leadsFound, createdAt] RadarLead: type: object properties: id: type: string searchId: type: string companyName: type: string phone: type: string nullable: true email: type: string nullable: true city: type: string state: type: string rating: type: number nullable: true hasWebsite: type: boolean hasWhatsapp: type: boolean instagramUrl: type: string nullable: true websiteUrl: type: string nullable: true status: type: string enum: [new, approached, added_crm, converted, rejected] aiApproach: type: string nullable: true createdAt: type: string format: date-time required: [id, searchId, companyName, city, state, hasWebsite, hasWhatsapp, status, createdAt] PaginatedRadarLeads: type: object properties: data: type: array items: $ref: "#/components/schemas/RadarLead" total: type: integer page: type: integer limit: type: integer totalPages: type: integer required: [data, total, page, limit, totalPages] LeadApproach: type: object properties: leadId: type: string approach: type: string generatedAt: type: string format: date-time required: [leadId, approach, generatedAt] ErpFinanceData: type: object properties: totalRevenue: type: number totalExpenses: type: number netProfit: type: number pendingPayments: type: number cashFlowChart: type: array items: $ref: "#/components/schemas/ChartDataPoint" recentTransactions: type: array items: $ref: "#/components/schemas/ErpTransaction" required: [totalRevenue, totalExpenses, netProfit, pendingPayments] ErpSalesData: type: object properties: totalSales: type: number salesCount: type: integer averageTicket: type: number topProducts: type: array items: type: object properties: name: type: string sales: type: number count: type: integer required: [name, sales, count] salesChart: type: array items: $ref: "#/components/schemas/ChartDataPoint" required: [totalSales, salesCount, averageTicket] ErpTransaction: type: object properties: id: type: string description: type: string amount: type: number type: type: string enum: [income, expense] category: type: string date: type: string format: date-time status: type: string enum: [pending, paid, cancelled] required: [id, description, amount, type, category, date, status] Task: type: object properties: id: type: string title: type: string description: type: string nullable: true status: type: string enum: [pending, in_progress, done] priority: type: string enum: [low, medium, high] assignedTo: type: string nullable: true dueAt: type: string format: date-time nullable: true createdAt: type: string format: date-time required: [id, title, status, priority, createdAt] CreateTaskRequest: type: object properties: title: type: string description: type: string nullable: true priority: type: string enum: [low, medium, high] default: medium assignedTo: type: string nullable: true dueAt: type: string format: date-time nullable: true required: [title] SalesReport: type: object properties: totalRevenue: type: number totalSales: type: integer averageTicket: type: number conversionRate: type: number chart: type: array items: $ref: "#/components/schemas/ChartDataPoint" required: [totalRevenue, totalSales, averageTicket, conversionRate] ConversationsReport: type: object properties: totalConversations: type: integer resolved: type: integer avgResponseTime: type: number botHandled: type: integer humanHandled: type: integer chart: type: array items: $ref: "#/components/schemas/ChartDataPoint" required: [totalConversations, resolved, avgResponseTime, botHandled, humanHandled] AiSettings: type: object properties: activeAgents: type: array items: type: string enum: [IA_ATENDENTE, IA_VENDEDOR, IA_AGENDA, IA_SENSE, IA_REATIVADOR, IA_ERP_INTERNO, IA_FINANCEIRO, IA_RELATORIOS, IA_RADAR_LEADS] systemPrompt: type: string nullable: true language: type: string default: pt-BR tone: type: string enum: [formal, casual, friendly, professional] businessDescription: type: string nullable: true required: [activeAgents, language, tone] UpdateAiSettingsRequest: type: object properties: activeAgents: type: array items: type: string systemPrompt: type: string nullable: true language: type: string tone: type: string enum: [formal, casual, friendly, professional] businessDescription: type: string nullable: true AutopilotSettings: type: object properties: enabled: type: boolean requireApprovalFor: type: array items: type: string enum: [charge, discount, reschedule, cancel_appointment, campaign, nfse] workingHours: type: object properties: enabled: type: boolean start: type: string end: type: string daysOfWeek: type: array items: type: integer required: [enabled, start, end, daysOfWeek] required: [enabled, requireApprovalFor, workingHours] TeamMember: type: object properties: id: type: string name: type: string email: type: string role: type: string enum: [MERCHANT_OWNER, MERCHANT_MANAGER, MERCHANT_AGENT, MERCHANT_FINANCE, MERCHANT_VIEWER] status: type: string enum: [active, invited, suspended] avatarUrl: type: string nullable: true lastActiveAt: type: string format: date-time nullable: true createdAt: type: string format: date-time required: [id, name, email, role, status, createdAt] InviteTeamMemberRequest: type: object properties: email: type: string format: email name: type: string role: type: string enum: [MERCHANT_MANAGER, MERCHANT_AGENT, MERCHANT_FINANCE, MERCHANT_VIEWER] required: [email, name, role] MerchantSubscription: type: object properties: id: type: string planId: type: string planName: type: string status: type: string enum: [trial, active, overdue, grace_period, final_notice, suspended, cancelled] amount: type: number currentPeriodEnd: type: string format: date-time trialEndsAt: type: string format: date-time nullable: true asaasPaymentLink: type: string nullable: true features: type: array items: $ref: "#/components/schemas/PlanFeature" required: [id, planId, planName, status, amount, currentPeriodEnd, features] Invoice: type: object properties: id: type: string amount: type: number status: type: string enum: [pending, paid, overdue, cancelled] dueDate: type: string format: date-time paidAt: type: string format: date-time nullable: true invoiceUrl: type: string nullable: true description: type: string createdAt: type: string format: date-time required: [id, amount, status, dueDate, description, createdAt] AsaasWebhookEvent: type: object properties: event: type: string payment: type: object nullable: true additionalProperties: true subscription: type: object nullable: true additionalProperties: true required: [event] EvolutionWebhookEvent: type: object properties: event: type: string instance: type: string data: type: object additionalProperties: true required: [event, instance, data]