import "dotenv/config"
import bcrypt from "bcrypt"
import { PrismaClient, UserRole } from "@prisma/client"

const prisma = new PrismaClient()

async function main() {
  const email = "nicolas.parreiras@mav.com.br"
  const password = "salocinnap"
  const name = "Nicolas Parreiras"

  const hash = await bcrypt.hash(password, 12)

  // garante tenant suporte (se você quiser amarrar nele)
  const tenant = await prisma.tenant.upsert({
    where: { id: "tenant-suporte" },
    update: {},
    create: {
      id: "tenant-suporte",
      name: "Meile (Suporte)",
      status: "ACTIVE",
    },
  })

  await prisma.user.upsert({
    where: { email },
    update: {
      name,
      role: UserRole.ADMIN,
      password: hash,
      tenantId: tenant.id,
    },
    create: {
      email,
      name,
      role: UserRole.ADMIN,
      password: hash,
      tenantId: tenant.id,
    },
  })

  console.log("Usuário criado/atualizado ✅")
  console.log("EMAIL:", email)
  console.log("SENHA:", password)
}

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