import fs from "fs";
import { MongoClient } from "mongodb";

const mongoClient = new MongoClient("mongodb://127.0.0.1:27017/local");
await mongoClient.connect();
const database = mongoClient.db("Nucleus");
const collection = database.collection("migrationTesting");

// Loop through all files in the oldData folder
const files = fs.readdirSync("./oldData");
let x = 0;
for (const file of files) {
    console.log(`┌ Processing file ${x} of ${files.length - 1} | ${file}`);
    // Read the file as a json
    let data;
    try {
        data = JSON.parse(fs.readFileSync(`./oldData/${file}`));
    } catch {
        console.log(`└ Error reading file ${file}`);
        x++;
        continue;
    }
    // Check if data version is 3
    if (data.version !== 3) {
        console.log(`├ Version was too old on ${file}`);
        console.log("└ Skipping file");
        x++;
        continue;
    }
    // Convert to the new format
    const newData = {
        id: data.guild_info.id.toString(),
        version: 1,
        singleEventNotifications: {
            statsChannelDeleted: false
        },
        filters: {
            images: {
                NSFW: !data.images.nsfw,
                size: data.images.toosmall
            },
            wordFilter: {
                enabled: true,
                words: {
                    strict: data.wordfilter.strict,
                    loose: data.wordfilter.soft
                }
            },
            invite: {
                enabled: data.invite ? data.invite.enabled : false,
                channels: data.invite ? data.invite.whitelist.channels.map((channel) => channel.toString()) : []
            },
            pings: {
                mass: 5,
                everyone: true,
                roles: true
            }
        },
        welcome: {
            enabled: data.welcome ? data.welcome.message.text !== null : false,
            verificationRequired: {
                message: null,
                role: null
            },
            role: data.welcome ? (data.welcome.role !== null ? data.welcome.role.toString() : null) : null,
            channel: data.welcome
                ? data.welcome.message.text !== null
                    ? data.welcome.message.channel.toString()
                    : null
                : null,
            message: data.welcome ? data.welcome.message.text : null
        },
        stats: {},
        logging: {
            logs: {
                enabled: true,
                channel: data.log_info.log_channel ? data.log_info.log_channel.toString() : null,
                toLog: "3fffff"
            },
            staff: {
                channel: data.log_info.staff ? data.log_info.staff.toString() : null
            }
        },
        verify: {
            enabled: data.verify_role !== null,
            role: data.verify_role ? data.verify_role.toString() : null
        },
        tickets: {
            enabled: data.modmail ? data.modmail.cat !== null : null,
            category: data.modmail ? (data.modmail.cat !== null ? data.modmail.cat.toString() : null) : null,
            types: "3f",
            customTypes: null,
            supportRole: data.modmail ? (data.modmail.mention !== null ? data.modmail.mention.toString() : null) : null,
            maxTickets: data.modmail ? data.modmail.max : 5
        },
        moderation: {
            mute: {
                timeout: true,
                role: null,
                text: null,
                link: null
            },
            kick: {
                text: null,
                link: null
            },
            ban: {
                text: null,
                link: null
            },
            softban: {
                text: null,
                link: null
            },
            warn: {
                text: null,
                link: null
            },
            role: {
                role: null
            }
        },
        tracks: [],
        roleMenu: [],
        tags: data.tags
    };
    // Insert the new data into the database
    await collection.updateOne({ id: data.guild_info.id.toString() }, { $set: newData }, { upsert: true });
    // Delete the old file
    fs.unlinkSync(`./oldData/${file}`);
    console.log(`└ Successfully migrated file ${file}`);
    x++;
}

// console.log((await collection.findOne({ id: "your mother" })));
