const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

async function main() {
  const tourId = '84d84c21-c12b-4a18-9655-043c85f5c0c5';
  const ownerUserId = '5b2053bb-f523-4a11-817c-f47fef7322bb'; // owner@travel.com

  // Check if owner@travel.com is already a participant
  const existing = await prisma.tourParticipant.findFirst({
    where: { tourId, userId: ownerUserId }
  });

  if (existing) {
    await prisma.tourParticipant.update({
      where: { id: existing.id },
      data: { role: 'OWNER' }
    });
    console.log('Updated existing participant to OWNER');
  } else {
    // Demote current owner to MEMBER or just keep them
    const result = await prisma.tourParticipant.create({
      data: {
        tourId,
        userId: ownerUserId,
        role: 'OWNER'
      }
    });
    console.log('Created new OWNER participant:', result);
  }
  
  // Update tour createdById to ownerUserId
  await prisma.tour.update({
    where: { id: tourId },
    data: { createdById: ownerUserId }
  });
  console.log('Updated tour creator to owner@travel.com');
}

main().catch(console.error).finally(() => prisma.$disconnect());
