// Creates an admin account from the command line.
// Usage: node scripts/createAdmin.js "Jane Doe" jane@bmmgrecords.com "StrongPassword123"
import dotenv from 'dotenv';
import { Admin } from '../src/models/Admin.js';
import { pool } from '../src/config/db.js';

dotenv.config();

const [, , name, email, password] = process.argv;

if (!name || !email || !password) {
  console.error('Usage: node scripts/createAdmin.js "<name>" <email> <password>');
  process.exit(1);
}

try {
  const existing = await Admin.findByEmail(email.toLowerCase().trim());
  if (existing) {
    console.error(`An admin with email ${email} already exists.`);
    process.exit(1);
  }

  const admin = await Admin.create({ name, email: email.toLowerCase().trim(), password });
  console.log('✓ Admin created:', { id: admin.id, name: admin.name, email: admin.email });
} catch (err) {
  console.error('Failed to create admin:', err.message);
  process.exit(1);
} finally {
  await pool.end();
}
