import { db } from "./db.ts";

const [username, password] = process.argv.slice(2);

if (!username || !password) {
    console.error("Usage: bun run register <username> <password>");
    process.exit(1);
}

const [existing] = await db`SELECT id FROM users WHERE username = ${username}`;
if (existing) {
    console.error(`User "${username}" already exists`);
    process.exit(1);
}

const passwordHash = await Bun.password.hash(password);
await db`INSERT INTO users (username, password_hash) VALUES (${username}, ${passwordHash})`;

console.log(`User "${username}" registered successfully`);
