// 관리자 계정 초기 생성 스크립트
// 사용: node src/scripts/createAdmin.js admin@example.com password123 관리자
const bcrypt = require('bcryptjs');
const prisma  = require('../config/db');

async function main() {
  const [,, email, password, nickname] = process.argv;
  if (!email || !password || !nickname) {
    console.error('사용법: node src/scripts/createAdmin.js <email> <password> <nickname>');
    process.exit(1);
  }
  const passwordHash = await bcrypt.hash(password, 12);
  const user = await prisma.user.upsert({
    where: { email },
    update: { passwordHash, role: 'admin', nickname },
    create: { email, passwordHash, nickname, role: 'admin', isEmailVerified: true },
  });
  console.log(`관리자 계정 생성/업데이트: ${user.email} (${user.id})`);
  await prisma.$disconnect();
}

main().catch(e => { console.error(e); process.exit(1); });
