import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

const ROLES = {
  PATIENT: "PATIENT",
  ASSISTANT: "ASSISTANT",
  THERAPIST: "THERAPIST",
} as const;

async function main() {
  console.log("🌱 Seeding database...");

  const therapist = await prisma.user.upsert({
    where: { phone: "+525512345678" },
    update: {},
    create: {
      email: "gloria@glorianino.com",
      phone: "+525512345678",
      name: "Gloria Niño",
      role: ROLES.THERAPIST,
      password: "admin123",
    },
  });

  console.log("✅ Created therapist:", therapist.name);

  const assistant = await prisma.user.upsert({
    where: { phone: "+525598765432" },
    update: {},
    create: {
      email: "asistente@glorianino.com",
      phone: "+525598765432",
      name: "Asistente Gloria",
      role: ROLES.ASSISTANT,
      password: "asistente123",
    },
  });

  console.log("✅ Created assistant:", assistant.name);

  const testPatient = await prisma.patient.upsert({
    where: { phone: "+52555555555" },
    update: {},
    create: {
      phone: "+52555555555",
      name: "Paciente Test",
      birthdate: new Date("1990-01-01"),
      email: "paciente@test.com",
      status: "active",
    },
  });

  console.log("✅ Created patient:", testPatient.name);

  const patientUser = await prisma.user.upsert({
    where: { phone: "+52555555555" },
    update: {},
    create: {
      email: "paciente@test.com",
      phone: "+52555555555",
      name: "Paciente Test",
      role: ROLES.PATIENT,
      password: "paciente123",
    },
  });

  console.log("✅ Created patient user:", patientUser.name);

  console.log("🎉 Seeding completed!");
}

main()
  .catch((e) => {
    console.error("❌ Seeding error:", e);
    process.exit(1);
  })
  .finally(async () => {
    await prisma.$disconnect();
  });
