/**
 * User model
 */

const { query, execute } = require('./baseModel');

async function findByUsername(username) {
  const rows = await query('SELECT * FROM User WHERE username = ? LIMIT 1', [username]);
  return rows[0] || null;
}

async function createUser({ username, password }) {
  const result = await execute('INSERT INTO User (username, password) VALUES (?, ?)', [username, password]);
  return { id: result.insertId, username };
}

module.exports = { findByUsername, createUser };

