import { connect } from "mongoose";
import WapServerList from "../../Models/WapServer/WapServer";
import {
    AssingAvailableServerParams,
    BotCheckSession,
    BotCheckStatus,
    BotEventParams,
    BotView,
    IWapServer,
    SendBotMessageParams,
} from "../../Models/WapServer/WapServer.Interface";

export class WapServerService {
    public async quitServer(data: AssingAvailableServerParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await WapServerList.quitServer(data);
    }
    public async assignAvailableServer(data: AssingAvailableServerParams): Promise<IWapServer> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        const server = await WapServerList.assignAvailableServer(data);
        return server;
    }

    public async createBot(data: BotEventParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await WapServerList.createBot(data);
    }

    public async startBot(data: BotEventParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await WapServerList.startBot(data);
    }

    public async stopBot(data: BotEventParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await WapServerList.stopBot(data);
    }

    public async deleteBot(data: BotEventParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await WapServerList.deleteBot(data);
    }

    public async checkBot(data: BotEventParams): Promise<BotCheckStatus> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return await WapServerList.checkBot(data);
    }

    public async checkSession(data: BotEventParams): Promise<BotCheckSession> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return await WapServerList.checkSession(data);
    }

    public async viewBot(data: BotEventParams): Promise<BotView> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return await WapServerList.botView(data);
    }

    public async getQr(data: BotEventParams): Promise<string> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        const pixBuf = await WapServerList.getQr(data);
        return pixBuf;
    }

    public async sendMessage(data: SendBotMessageParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await WapServerList.sendMessage(data);
    }
}
