import { prisma } from '../src/config/database.js';
import { hashPassword } from '../src/utils/password.js';

async function main() {
  const ivan = await prisma.user.findUnique({ where: { email: 'ivan@horuxfin.com' }, include: { tenant: true } });
  if (!ivan) { console.error('Ivan not found'); process.exit(1); }

  console.log('Tenant:', ivan.tenant.nombre, '(', ivan.tenant.id, ')');

  const existing = await prisma.user.findUnique({ where: { email: 'carlos@horuxfin.com' } });
  if (existing) { console.log('Carlos already exists:', existing.id); process.exit(0); }

  const hash = await hashPassword('Aasi940812');
  const carlos = await prisma.user.create({
    data: {
      tenantId: ivan.tenantId,
      email: 'carlos@horuxfin.com',
      passwordHash: hash,
      nombre: 'Carlos Horux',
      role: 'admin',
    }
  });
  console.log('Carlos created:', carlos.id, carlos.email, carlos.role);
}

main().then(() => process.exit(0)).catch(e => { console.error(e); process.exit(1); });
