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

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

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

const createAuditStatus = async (audit_status_id, audit_status_name) => {
  await pool.query('INSERT INTO sat_audit_status (audit_status_id, audit_status_name) VALUES (?, ?)', [audit_status_id, audit_status_name]);
};

const updateAuditStatus = async (id, audit_status_name) => {
  const [result] = await pool.query('UPDATE sat_audit_status SET audit_status_name = ? WHERE audit_status_id = ?', [audit_status_name, id]);
  return result.affectedRows > 0;
};

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

module.exports = {
  getAllAuditStatuses,
  getAuditStatusById,
  createAuditStatus,
  updateAuditStatus,
  deleteAuditStatus
};

