import { NextResponse } from 'next/server'
import bcrypt from 'bcryptjs'
import { db } from '@/lib/db'

export async function POST() {
  try {
    const existing = await db.employe.findUnique({
      where: { email: 'admin@optiquestock.com' },
    })

    if (existing) {
      return NextResponse.json({ message: 'Admin already exists' })
    }

    const hashedPassword = await bcrypt.hash('admin123', 12)

    const employe = await db.employe.create({
      data: {
        email: 'admin@optiquestock.com',
        nom: 'Admin',
        prenom: 'Admin',
        role: 'ADMIN',
        motDePasse: hashedPassword,
      },
    })

    return NextResponse.json({
      message: 'Admin user created',
      email: employe.email,
      password: 'admin123',
    })
  } catch (error) {
    console.error('Seed error:', error)
    return NextResponse.json({ error: 'Seed failed' }, { status: 500 })
  }
}
