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

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

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

const createTicketsStatus = async (status_id, status_type) => {
  await pool.query('INSERT INTO tickets_status (status_id, status_type) VALUES (?, ?)', [status_id, status_type]);
};

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

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

module.exports = {
  getAllTicketsStatuses,
  getTicketsStatusById,
  createTicketsStatus,
  updateTicketsStatus,
  deleteTicketsStatus
};

