import { normalizeEmail } from './auth.js'
import { prisma } from './prisma.js'

export async function ensureAdminUser() {
  const adminEmail = normalizeEmail(process.env.ADMIN_EMAIL)
  if (!adminEmail) return
  if (!adminEmail.includes('@')) {
    throw new Error('ADMIN_EMAIL должен быть валидным email')
  }

  await prisma.user.upsert({
    where: { email: adminEmail },
    update: {},
    create: { email: adminEmail },
  })
}
