import type { Bot } from '../bots/types' import type { Department } from '../departments/types' export type ServiceType = | 'whatsapp' | 'email' | 'webchat' | 'sms-wavy' | 'telegram' | 'instagram' | 'reclame-aqui' | 'whatsapp-remote' | 'whatsapp-business' | 'facebook-messenger' | 'google-business-message' export type ServiceConnectionStatus = { isSyncing?: boolean isConnected?: boolean isStarting?: boolean isStarted?: boolean batteryLevel?: number isCharging?: boolean isConflicted?: boolean isLoading?: boolean isOnChatPage?: boolean enteredQrCodePageAt?: string disconnectedAt?: string isOnQrPage?: boolean isPhoneAuthed?: boolean isPhoneConnected?: boolean isQrCodeExpired?: boolean isHosted?: boolean isWaitingForPhoneInternet?: boolean isWebConnected?: boolean isWebSyncing?: boolean isLidMigrated?: boolean mode?: string myId?: string myLidId?: string myName?: string myNumber?: string needsCharging?: boolean qrCodeExpiresAt?: number qrCodeUrl?: string | null state?: string timestamp?: string } export type ServiceData = { // ─── Common ─────────────────────────────────────────────────────────────── token?: string myId?: string syncCount?: number readReceipts?: boolean markComposingBeforeSend?: boolean lastSyncAt?: string lastDisconnectedAt?: string lastMessageTimestamp?: string isManuallyDisconnected?: boolean notifiedServiceDisconnectionAt?: string status?: ServiceConnectionStatus // ─── WhatsApp / WhatsApp Remote ─────────────────────────────────────────── phone?: string phoneWhatsapp?: string provider?: string appName?: string syncFlowDone?: boolean // ─── WhatsApp Business ──────────────────────────────────────────────────── pageId?: string businessId?: string numberId?: string /** WhatsApp Business API provider: positus, 360Dialog, meta, or gupshup. */ providerType?: 'positus' | '360Dialog' | 'meta' | 'gupshup' | null hub360PartnerId?: string // ─── Telegram ───────────────────────────────────────────────────────────── nameTelegram?: string // ─── Email ──────────────────────────────────────────────────────────────── /** Email service provider. */ service?: 'Gmail' | 'Outlook365' | 'Godaddy' | 'GSuite' | 'Hotmail' | 'other' | null auth?: { user: string; pass?: string } imap?: { host: string; port: number; syncFrom: number } smtp?: { host: string; port: number; ignoreTLS?: boolean; requireTLS?: boolean } includeSpamTrash?: boolean microsoft?: { token_type: string scope: string expires_in: number ext_expires_in: number access_token: string refresh_token: string refreshedAt: string } // ─── SMS Wavy ───────────────────────────────────────────────────────────── smsWavy?: { sync: boolean } // ─── Webchat ────────────────────────────────────────────────────────────── nameWebchat?: string filePerfilWebchat?: { base64Url: string mimetype: string fileName: string } webchat?: Record // ─── Other ──────────────────────────────────────────────────────────────── driverId?: string apiURL?: string error?: unknown googleBusiness?: unknown } export type ServiceInternalData = { id?: string appToken?: string partnerToken?: string apiKey?: string webchat?: { id: string token: string password: string username: string } user?: string pass?: string clientId?: string clientSecret?: string securityToken?: string token?: { accessToken: string tokenType: string expiresAt: number scope: string rateLimit: number licenseStartAt: string licenseId: number organizationId: string } localStorage?: Record envInfo?: Record mmlite?: string } | null export type ServiceSettings = { readReceipts?: boolean markComposingBeforeSend?: boolean blockMessageRulesActive?: boolean unblockByReceiveMessage?: boolean shouldOpenTicketForGroups?: boolean reactionsEnabled?: boolean tokenSandBox360?: string lowLevel?: boolean cloudApi?: boolean keepOnline?: boolean allowScanAnotherNumber?: boolean contactsSyncDisabled?: boolean legacyMessageIds?: boolean ackChangeTimeout?: number fallbackMessagesCheckerInterval?: number disableMessagesChecker?: boolean disableFallbackMessagesChecker?: boolean syncDelay?: number lowLevelContactCheckerDelay?: number lowLevelStatusConnectedDelay?: number widget?: Record } /** WhatsApp Business API health status (WABA only). */ export type ServiceHealth = { /** e.g. `'AVAILABLE'` | `'LIMITED'` | `'BLOCKED'` */ status: string /** e.g. `'ALLOWED'` | `'BLOCKED'` | `'LIMITED'` */ canSendMessage: string /** e.g. `'HIGH'` | `'MEDIUM'` | `'LOW'` */ qualityRating: string info: string errors: { description: string; solution: string }[] } export type Service = { id: string name: string type: ServiceType data: ServiceData internalData: ServiceInternalData settings: ServiceSettings health: ServiceHealth | null accountId: string defaultDepartmentId: string | null botId: string | null archivedAt: string | null createdAt: string updatedAt: string deletedAt: string | null // relationships bot?: Bot | null defaultDepartment?: Department | null } export type ServiceRelationships = 'bot' | 'defaultDepartment' export type CreateServicePayload = { name: string type: ServiceType data?: ServiceData settings?: ServiceSettings defaultDepartmentId?: string botId?: string } export type UpdateServicePayload = { name?: string data?: ServiceData settings?: ServiceSettings defaultDepartmentId?: string | null botId?: string | null archivedAt?: string | null }