
import { AuthService } from './src/services/auth.service';
import prisma from './src/lib/prisma';
import bcrypt from 'bcryptjs';

// const prisma = new PrismaClient(); // Removed local instance

async function run() {
    try {
        console.log("Setting up test user...");
        const email = 'repro_user@gymflow.ai';
        const password = 'password123';
        const hashed = await bcrypt.hash(password, 10);

        await prisma.user.upsert({
            where: { email },
            update: { password: hashed, isBlocked: false },
            create: {
                email,
                password: hashed,
                role: 'USER',
                profile: { create: { weight: 70 } }
            }
        });

        console.log("Attempting login...");
        const result = await AuthService.login(email, password);
        console.log("Login success:", result ? "OK" : "No result");
    } catch (error) {
        console.error("Login failed with error:");
        console.error(error);
    } finally {
        await prisma.$disconnect();
    }
}

run();
