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,
            },
            "welcomeRole": 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" })));
