import * as argon from "@node-rs/argon2";
import { PrismaService } from "src/prisma/prisma.service";

const prisma = new PrismaService();

async function main() {
    console.log("🔐 Updating user passwords...");

    const users = [
        ["fitra@superemas.id", "Fitra0101"],
        ["farhan@superemas.id", "Farhan1212"],
        ["julio@superemas.id", "Julio9999"],
        ["fanny.dwi@superemas.id", "Fanny4422"],
        ["ananda.febiani@superemas.id", "Febi5555"],
        ["faradila.nayafa@superemas.id", "Dila3344"],
        ["sindy.amelia@superemas.id", "Sindy0033"],
        ["tenggo.vanhegar@superemas.id", "Tenggo8787"],
        ["umamsyah.mujidin@superemas.id", "Umam4949"],
        ["adji.putra@superemas.id", "Adji1010"],
        ["thomas.ardho@superemas.id", "Thomas2323"],
        ["syah.rani@superemas.id", "Rani9876"],
        ["alin.arimbi@superemas.id", "Alin1199"],
        ["ananda.pratama@superemas.id", "Nanda5566"],
        ["catherine.rara@superemas.id", "Catherine2525"],
        ["dani.prihat@superemas.id", "Dani7676"],
    ];

    for (const [email, plainPassword] of users) {
        const hashed = await argon.hash(plainPassword);

        const updated = await prisma.user.updateMany({
            where: { email },
            data: { hash: hashed },
        });

        if (updated.count === 0) {
            console.warn(`⚠️ User not found: ${email}`);
        } else {
            console.log(`✅ Updated password: ${email}`);
        }
    }

    console.log("🎉 Done updating passwords.");
}

main()
    .catch((e) => {
        console.error("❌ Error:", e);
        process.exit(1);
    })
    .finally(async () => {
        await prisma.$disconnect();
    });