const pool = require("../config/db");

const getAllAccountStatuses = async () => {
  const [rows] = await pool.query('SELECT * FROM account_status');
  return rows;
};

const getAccountStatusById = async (id) => {
  const [rows] = await pool.query('SELECT * FROM account_status WHERE status_id = ?', [id]);
  return rows.length ? rows[0] : null;
};

const createAccountStatus = async (status_id, status_name) => {
  await pool.query('INSERT INTO account_status (status_id, status_name) VALUES (?, ?)', [status_id, status_name]);
};

const updateAccountStatus = async (id, status_name) => {
  const [result] = await pool.query('UPDATE account_status SET status_name = ? WHERE status_id = ?', [status_name, id]);
  return result.affectedRows > 0;
};

const deleteAccountStatus = async (id) => {
  const [result] = await pool.query('DELETE FROM account_status WHERE status_id = ?', [id]);
  return result.affectedRows > 0;
};

module.exports = {
  getAllAccountStatuses,
  getAccountStatusById,
  createAccountStatus,
  updateAccountStatus,
  deleteAccountStatus
};

