require('dotenv').config();
const { query, pool } = require('./src/utils/db');
const bcrypt = require('bcryptjs');

async function createAdmin() {
  try {
    const hash = await bcrypt.hash('Admin1234', 12);
    const result = await query(
      `INSERT INTO admins (email, password_hash, name, role)
       VALUES ($1, $2, $3, 'super_admin')
       ON CONFLICT (email) DO UPDATE SET password_hash = $2
       RETURNING id, email, name, role`,
      ['admin@mastreams.mw', hash, 'Super Admin']
    );
    console.log('✅ Admin created:', result.rows[0]);
  } catch (err) {
    console.error('❌ Failed:', err.message);
  } finally {
    await pool.end();
  }
}

createAdmin();