import {fakerNL_BE} from '@faker-js/faker'
import type {SexType} from '@faker-js/faker'
import type {Prisma, PrismaClient} from '@/generated/prisma/client'

export const seedDev = async (prisma: PrismaClient) => {
  const contacts: Prisma.ContactCreateManyInput[] = []

  for (let i = 0; i < 20; i++) {
    const sex = fakerNL_BE.person.sex() as SexType
    const firstName = fakerNL_BE.person.firstName(sex)
    const lastName = fakerNL_BE.datatype.boolean() ? fakerNL_BE.person.lastName(sex) : null
    const description = fakerNL_BE.lorem.sentence()

    const contactInfoMap: Record<string, () => string> = {
      email: () => fakerNL_BE.internet.email({firstName: firstName, lastName: lastName ?? undefined}),
      phone: () => fakerNL_BE.phone.number(),
      address: () =>
        fakerNL_BE.location.streetAddress() + ' ' + fakerNL_BE.location.zipCode() + ' ' + fakerNL_BE.location.city(),
      'work phone': () => fakerNL_BE.phone.number(),
      'work email': () => fakerNL_BE.internet.email({firstName: firstName, lastName: lastName ?? undefined}),
      'work place': () => fakerNL_BE.company.name(),
      'job title': () => fakerNL_BE.person.jobTitle(),
    }

    contacts.push({
      id: fakerNL_BE.string.uuid(),
      firstName,
      lastName,
      description,
      avatar: `/avatars/${sex}/AV${sex === 'female' ? fakerNL_BE.number.int({min: 51, max: 100}) : fakerNL_BE.number.int({min: 1, max: 50})}.png`,
      contactInfo: Object.keys(contactInfoMap)
        .filter(() => fakerNL_BE.datatype.boolean())
        .map(k => ({type: k, value: contactInfoMap[k]()})),
      favorite: i % 5 === 0,
    })
  }

  await prisma.contact.createMany({
    data: contacts,
  })
}
