import { config } from './config.js';
import { hashPassword } from './crypto.js';
import { migrate } from './db.js';
import { getUserByUsername, setUserPassword } from './store.js';

migrate();

const username = process.argv[2] || config.authUsername;
const password = process.argv[3] || config.authPassword;

if (!username || !password) {
  console.error('Usage: node src/reset-password.js <username> <password>');
  process.exit(1);
}

const user = getUserByUsername(username);
if (!user) {
  console.error(`User "${username}" was not found.`);
  process.exit(1);
}

setUserPassword(username, hashPassword(password));
console.log(`Password updated for ${username}.`);
