import os from 'os';
import dir from 'path';
import fs from 'fs';
import path from 'path';

// Delete a directory and its children 
export const createSessionDir = () => {

    console.log('process.cwd(): ', process.cwd())

    const wwebjsAuthPath = dir.join(process.cwd(), '.wwebjs_auth');
    const sessionPath = dir.join(process.cwd(), '.wwebjs_auth', 'sessions');
    const sessionLogPath = dir.join(process.cwd(), '.wwebjs_auth', 'sessions','log');

    fs.access(wwebjsAuthPath, (error) => {
        // To check if the given directory 
        // already exists or not
        if (error) {
            // If current directory does not exist
            // then create it
            fs.mkdir(wwebjsAuthPath, (error) => {
                if (error) {
                    console.log(error);
                } else {
                    console.log(`wwebjs_auth Directory created successfully !!!`);
                }
            });
        } else {
            console.log("wwebjs_auth Directory already exists !!");
        }
    });


    fs.access(sessionPath, (error) => {
        // To check if the given directory 
        // already exists or not
        if (error) {
            // If current directory does not exist
            // then create it
            fs.mkdir(sessionPath, (error) => {
                if (error) {
                    console.log(error);
                } else {
                    console.log(`sessions Directory created successfully !!!`);
                }
            });
        } else {
            console.log("sessions Directory already exists !!");
        }
    });

    fs.access(sessionLogPath, (error) => {

        // To check if the given directory 
        // already exists or not
        if (error) {
            // If current directory does not exist
            // then create it
            fs.mkdir(sessionLogPath, (error) => {
                if (error) {
                    console.log(error);
                } else {
                    console.log(`log Directory created successfully !!!`);
                }
            });
        } else {
            console.log("log Directory already exists !!");
        }
    });


}