"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const RestoreControll_1 = require("./RestoreControll");
const fsPromises = require("fs/promises");
const fs = require('fs');
const socket_1 = require("../libs/socket");
const autoRestore = (whatsappId, started_action_by = '') => __awaiter(void 0, void 0, void 0, function* () {
    /*const whatsapp = await ShowWhatsAppService(whatsappId);

    // console.log('>>>>>>>>>>> Whatsapp.id: ', whatsappId)

    await restartWhatsSession(whatsapp, true)


    const sourcePath = path.join(__dirname, `../../.wwebjs_auth/sessions/log`)

    if (fs.existsSync(sourcePath)) {

        let log = new Date(new Date() + 'UTC');

        const dateToday = splitDateTime(new Date(format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR })))

        let timestamp = Math.floor(Date.now() / 1000)

        let number: any = whatsapp.number

        if (!number) {
            number = ''
        }

        if (started_action_by.trim().length > 0)
            fs.writeFileSync(`${sourcePath}/${timestamp}_restore_${number}_triggered_by_${started_action_by}_id_${whatsappId}.txt`, `Whatsapp id: ${whatsapp.id} \nDate: ${dateToday.fullDate} ${dateToday.fullTime}`, (error: any) => { console.log(error) });

    }*/
    RestoreControll_1.setRestoreControll({ 'id': +whatsappId, 'disabled': true });
    let lstRestore = RestoreControll_1.getRestoreControll();
    const io = socket_1.getIO();
    io.emit("whatsappSession", {
        action: "update",
        session: { 'id': +whatsappId, 'disabled': true }
    });
    setTimeout(() => {
        let whatsapp = RestoreControll_1.shifRestoreControll();
        whatsapp.disabled = false;
        io.emit("whatsappSession", {
            action: "update",
            session: whatsapp
        });
    }, 25000);
});
exports.default = autoRestore;
