"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());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.restartWhatsSession = void 0;
const path_1 = __importDefault(require("path"));
const wbot_1 = require("../libs/wbot");
const StartWhatsAppSession_1 = require("../services/WbotServices/StartWhatsAppSession");
const CopyFolder_1 = require("./CopyFolder");
const DeleteDirectory_1 = require("./DeleteDirectory");
// import internetConnection from "./InternetConnection";
const fsPromises = require("fs/promises");
const fs = require('fs');
// Restart session
const restartWhatsSession = (whatsapp, backupSession = false) => __awaiter(void 0, void 0, void 0, function* () {
    return;
    console.log('RESTARTING THE whatsapp.id: ', whatsapp.id);
    const sourcePath = path_1.default.join(__dirname, `../../.wwebjs_auth/sessions/`, `session-bd_${whatsapp.id}`);
    const destPath = path_1.default.join(__dirname, `../../.wwebjs_auth/`, `session-bd_${whatsapp.id}`);
    console.log('================> sourcePath: ', sourcePath);
    console.log('================> destPath: ', destPath);
    wbot_1.removeWbot(whatsapp.id);
    yield DeleteDirectory_1.removeDir(destPath);
    if (fs.existsSync(sourcePath)) {
        // copy the good session for restars the new session
        CopyFolder_1.copyFolder(sourcePath, destPath);
    }
    else {
        console.log('Directory not found to copy: ', sourcePath);
    }
    console.log('RESTARTING SESSION...');
    // await StartWhatsAppSession(whatsapp, backupSession); 
    setTimeout(() => StartWhatsAppSession_1.StartWhatsAppSession(whatsapp, backupSession), 2000);
});
exports.restartWhatsSession = restartWhatsSession;
