import dotenv from 'dotenv';
dotenv.config({ path: '.env.local' });

import { prisma } from '../lib/db';

async function checkAdminUser() {
  try {
    console.log('Checking admin user: andrei@cloudz.ro');

    const user = await prisma.user.findUnique({
      where: { email: 'andrei@cloudz.ro' },
      select: {
        id: true,
        email: true,
        name: true,
        role: true,
        createdAt: true,
        lastLoginAt: true
      }
    });

    if (user) {
      console.log('✅ User found:', user);

      if (['admin', 'moderator'].includes(user.role)) {
        console.log('✅ User has admin privileges');
      } else {
        console.log('❌ User does not have admin role. Current role:', user.role);
        console.log('Updating user role to admin...');

        const updatedUser = await prisma.user.update({
          where: { email: 'andrei@cloudz.ro' },
          data: { role: 'admin' }
        });

        console.log('✅ User role updated:', updatedUser.role);
      }
    } else {
      console.log('❌ User not found');
    }
  } catch (error) {
    console.error('Error checking admin user:', error);
  } finally {
    await prisma.$disconnect();
  }
}

checkAdminUser();