import { db } from '@/lib/db';
import { hash } from 'bcryptjs';

async function main() {
  const user = await db.user.create({
    data: {
      email: 'user@user.com',
      username: 'user',
      emailVerified: new Date(),
      password: await hash('password', 10),
      role: 'USER',
    },
  });

  const contributor = await db.user.create({
    data: {
      email: 'contributor@contributor.com',
      username: 'contributor',
      emailVerified: new Date(),
      password: await hash('password', 10),
      role: 'USER',
    },
  });

  const admin = await db.user.create({
    data: {
      email: 'admin@admin.com',
      username: 'admin',
      emailVerified: new Date(),
      password: await hash('password', 10),
      role: 'ADMIN',
    },
  });

  console.log('Seeded users:', user, contributor, admin);

  const project1 = await db.project.create({
    data: {
      title: 'Portfolio Builder',
      description: 'A sleek portfolio creator for developers.',
      url: 'https://example.com/portfolio-builder',
      image: 'https://picsum.photos/600/352',
      technologies: ['React', 'Next.js', 'TailwindCSS'],
      userId: user.id,
    },
  });

  const project2 = await db.project.create({
    data: {
      title: 'E-commerce Platform',
      description: 'An online store with full shopping cart and payment integration.',
      url: 'https://example.com/e-commerce',
      image: 'https://picsum.photos/600/352',
      technologies: ['React', 'Next.js', 'TailwindCSS'],
      userId: contributor.id,
    },
  });

  console.log('Seeded projects:', project1, project2);

  const portfolio = await db.portfolio.create({
    data: {
      title: "User's Portfolio",
      is_published: false,
      ownerId: user.id,
    },
  });

  console.log('Seeded portfolio:', portfolio);

  const portfolioInvitation = await db.portfolioContributor.create({
    data: {
      portfolioId: portfolio.id,
      userId: contributor.id,
      status: 'PENDING',
    },
  });

  console.log('Seeded portfolio invitation:', portfolioInvitation);

  const portfolioProjects = await db.portfolioProject.createMany({
    data: [
      {
        portfolioId: portfolio.id,
        projectId: project1.id,
        status: 'APPROVED',
      },
      {
        portfolioId: portfolio.id,
        projectId: project2.id,
        status: 'PENDING',
      },
    ],
  });

  console.log('Seeded portfolio projects:', portfolioProjects);
}

main()
  .catch((e) => {
    console.error(e);
    process.exit(1);
  })
  .finally(async () => {
    await db.$disconnect();
  });
