/**
 * Quick script to reset the admin user password for E2E testing.
 * Usage: node reset-admin.mjs <newpassword>
 */
import Database from 'better-sqlite3';
import bcrypt from 'bcrypt';
import { fileURLToPath } from 'url';
import path from 'path';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const DB_PATH = path.resolve(__dirname, '../data/metadata.db');
const newPassword = process.argv[2] || 'Admin@2026';

const db = new Database(DB_PATH);

const hashed = await bcrypt.hash(newPassword, 10);
const result = db.prepare("UPDATE users SET password = ? WHERE username = 'admin'").run(hashed);

if (result.changes > 0) {
    console.log(`✅ Admin password reset to: ${newPassword}`);
} else {
    console.log('❌ Admin user not found');
}
db.close();
