import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient(); async function main() { console.log('🌱 Seeding Fase 3 - Torneos y Ligas...\n'); const admin = await prisma.user.findUnique({ where: { email: 'admin@padel.com' } }); if (!admin) { console.log('āŒ Admin no encontrado. Ejecuta seed.ts primero.'); return; } const courts = await prisma.court.findMany({ where: { isActive: true }, take: 2 }); const courtIds = JSON.stringify(courts.map(c => c.id)); // Crear torneo de eliminatoria const tournament1 = await prisma.tournament.upsert({ where: { id: 'tour-1' }, update: {}, create: { id: 'tour-1', name: 'Torneo de Verano 2024', description: 'Torneo eliminatorio mixto para todos los niveles', type: 'ELIMINATION', category: 'MIXED', allowedLevels: JSON.stringify(['BEGINNER', 'ELEMENTARY', 'INTERMEDIATE']), maxParticipants: 16, registrationStartDate: new Date(), registrationEndDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), startDate: new Date(Date.now() + 14 * 24 * 60 * 60 * 1000), endDate: new Date(Date.now() + 21 * 24 * 60 * 60 * 1000), courtIds: courtIds, price: 2000, status: 'OPEN', createdById: admin.id, }, }); console.log(`āœ… Torneo creado: ${tournament1.name}`); // Crear torneo round robin const tournament2 = await prisma.tournament.upsert({ where: { id: 'tour-2' }, update: {}, create: { id: 'tour-2', name: 'Liga de Invierno - Individual', description: 'Liga todos contra todos', type: 'ROUND_ROBIN', category: 'MEN', allowedLevels: JSON.stringify(['INTERMEDIATE', 'ADVANCED', 'COMPETITION']), maxParticipants: 8, registrationStartDate: new Date(), registrationEndDate: new Date(Date.now() + 10 * 24 * 60 * 60 * 1000), startDate: new Date(Date.now() + 17 * 24 * 60 * 60 * 1000), endDate: new Date(Date.now() + 60 * 24 * 60 * 60 * 1000), courtIds: courtIds, price: 3000, status: 'DRAFT', createdById: admin.id, }, }); console.log(`āœ… Torneo creado: ${tournament2.name}`); // Crear una liga por equipos const league = await prisma.league.upsert({ where: { id: 'league-1' }, update: {}, create: { id: 'league-1', name: 'Liga de Club 2024', description: 'Liga interna del club por equipos', format: 'SINGLE_ROUND_ROBIN', startDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), endDate: new Date(Date.now() + 90 * 24 * 60 * 60 * 1000), status: 'DRAFT', createdById: admin.id, }, }); console.log(`āœ… Liga creada: ${league.name}`); console.log('\nšŸŽ¾ Fase 3 seed completado!'); console.log('\nDatos creados:'); console.log(` - 2 Torneos (Eliminatoria, Round Robin)`); console.log(` - 1 Liga por equipos`); } main() .catch((e) => { console.error(e); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });