import { IPayload } from "../SysAdminPayload/SysAdminPayload.interface"; import { IWapServerDocument } from "./WapServer.Adapter.Mongoose"; export type FindWapServerParams = { id?: string; name?: string; description?: string; countBots?: number; maxBots?: number; port?: number; active?: boolean; countBotsFrom?: number; countBotsTo?: number; }; export type AssingAvailableServerParams = { companyId: string; sessionUser: string; }; export type BotEventParams = AssingAvailableServerParams & {}; export type BotRunningStatus = | "created" | "running" | "paused" | "restarting" | "removing" | "exited" | "dead"; export type BotEventError = { error: string; code: number; }; export enum SERVER_STATE { "RUNNING" = "running", "NOT_WORKING" = "not_working", "NOT_ASSIGNED" = "not_assigned", } export enum BOT_STATE { "EXISTS" = "exists", "NOT_EXISTS" = "not_exists", } export enum BOT_SESSION_STATUS { "LOGED" = "ok", "UNLOGED" = "fail", } export type BotCheckStatus = { state: BOT_STATE; status: BotRunningStatus; serverState: SERVER_STATE; }; export type BotCheckSession = { session: BOT_SESSION_STATUS; }; export type SendBotMessageParams = { companyId: string; number: string; message: string; sessionUser: string; }; export enum VALIDATE_BOT_ENVENT_ERRORS { "INVALID_USER" = "invalid_user", "INVALID_ORG" = "invalid_org", "NO_PERMISSION" = "no_permission", "NO_BOT_ALLOWED" = "no_bot_allowed", "NO_SUBSCRIPTION_ACTIVE" = "no_subscription_active", "NO_SERVER_ASSIGNED" = "no_server_assigned", } export interface ValidateBotEventStatus { status: boolean; error: string; serverUrl?: string; code?: VALIDATE_BOT_ENVENT_ERRORS; } export interface BotView { exists: boolean; runningState: BotRunningStatus; serverId?: string; serverName?: string; serverDescription?: string; serverState?: SERVER_STATE; botSession?: BOT_SESSION_STATUS; automaticNotifications: boolean; } export interface IWapServer { id?: string; name?: string; description?: string; ipv4: string; ipv6: string; countBots: number; maxBots: number; port: number; active: boolean; } export type UpdateWapServerParams = { serverId: string; name?: string; ipv4?: string; port?: number; maxBots?: number; active?: boolean; }; export type PaginateWapServerParams = FindWapServerParams & { page: number; limit: number; }; export type PaginateWapServerResults = { data: IWapServer[]; page: number; pages: number; }; export type SysAdminWapServerByIdParams = { serverId: string; }; export type SysAdminWapServerAuditParams = SysAdminWapServerByIdParams; export type SysAdminWapServerRecalculateCountParams = SysAdminWapServerByIdParams; export type SysAdminDeleteWapServerParams = SysAdminWapServerByIdParams; export type SysAdminDeleteWapServerResult = { serverId: string; deleted: true; }; export type SysAdminWapServerOrganizationActionParams = SysAdminWapServerByIdParams & { organizationId: string; }; export type SysAdminWapServerQrResult = { serverId: string; organizationId: string; qr: string; }; export type SysAdminWapServerDetachResult = { serverId: string; organizationId: string; botDeleted: boolean; botAlreadyMissing: boolean; before: number; after: number; }; export type SysAdminWapServerDeleteBotResult = { serverId: string; organizationId: string; assignmentRemains: true; before: number; after: number; }; export type SysAdminWapAssignedOrganization = { id: string; name?: string; }; export type SysAdminWapContainerDto = { id?: string; name?: string; organizationId?: string; image?: string; state?: string; status?: string; ports?: unknown[]; created?: number; }; export type SysAdminWapServerAuditResult = { serverId: string; assignedOrganizations: SysAdminWapAssignedOrganization[]; detectedBots: SysAdminWapContainerDto[]; validBots: SysAdminWapContainerDto[]; ghostBots: SysAdminWapContainerDto[]; missingBots: SysAdminWapAssignedOrganization[]; expectedCountBots: number; storedCountBots: number; runtimeCountBots: number; countMismatch: boolean; }; export type SysAdminWapServerRecalculateCountResult = { serverId: string; before: number; after: number; }; export type SysAdminGetWapServerParams = PaginateWapServerParams & { payload: IPayload; }; export type SysAdminUpdateWapServerParams = UpdateWapServerParams & { payload: IPayload; }; export type SysAdminAuditWapServerParams = SysAdminWapServerAuditParams & { payload: IPayload; }; export type SysAdminRecalculateWapServerCountParams = SysAdminWapServerRecalculateCountParams & { payload: IPayload; }; export type SysAdminDeleteWapServerRequest = SysAdminDeleteWapServerParams & { payload: IPayload; }; export type SysAdminWapServerOrganizationActionRequest = SysAdminWapServerOrganizationActionParams & { payload: IPayload; }; export interface IWapServerAdapter { find(data: FindWapServerParams): Promise; findOne(data: FindWapServerParams): Promise; delete(id: string): Promise; paginate(filters: PaginateWapServerParams): Promise; } export interface IWapServerManager { servers: IWapServerAdapter; findServers(): Promise; getAvailableServer(): Promise; assignAvailableServer(data: AssingAvailableServerParams): Promise; quitServer(data: AssingAvailableServerParams): Promise; createBot(data: BotEventParams): Promise; startBot(data: BotEventParams): Promise; stopBot(data: BotEventParams): Promise; deleteBot(data: BotEventParams): Promise; checkBot(data: BotEventParams): Promise; checkSession(data: BotEventParams): Promise; botView(data: BotEventParams): Promise; getQr(data: BotEventParams): Promise; sendMessage(data: SendBotMessageParams): Promise; sysAdminGetWapServers(data: PaginateWapServerParams): Promise; sysAdminUpdateWapServer(data: UpdateWapServerParams): Promise; sysAdminAuditWapServer(data: SysAdminWapServerAuditParams): Promise; sysAdminRecalculateWapServerCount(data: SysAdminWapServerRecalculateCountParams): Promise; sysAdminDeleteWapServer(data: SysAdminDeleteWapServerParams): Promise; sysAdminStartBot(data: SysAdminWapServerOrganizationActionParams): Promise; sysAdminStopBot(data: SysAdminWapServerOrganizationActionParams): Promise; sysAdminRestartBot(data: SysAdminWapServerOrganizationActionParams): Promise; sysAdminGetQr(data: SysAdminWapServerOrganizationActionParams): Promise; sysAdminDeleteBot(data: SysAdminWapServerOrganizationActionParams): Promise; sysAdminDetachOrganizationServer(data: SysAdminWapServerOrganizationActionParams): Promise; }