const db = require('../config/db.js');

class Admin {
  static async findByUsername(username) {
    const [rows] = await db.query('SELECT * FROM admins WHERE username = ?', [username]);
    return rows[0] || null;
  }

  static async create({ username, password }) {
    const [result] = await db.query(
      'INSERT INTO admins (username, password) VALUES (?, ?)',
      [username, password]
    );
    return { id: result.insertId, username };
  }

  static async count() {
    const [rows] = await db.query('SELECT COUNT(*) as count FROM admins');
    return rows[0].count;
  }
}

module.exports = Admin;
