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

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

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

const createQuestionType = async (question_type_id, question_type) => {
  await pool.query('INSERT INTO sat_question_type (question_type_id, question_type) VALUES (?, ?)', [question_type_id, question_type]);
};

const updateQuestionType = async (id, question_type) => {
  const [result] = await pool.query('UPDATE sat_question_type SET question_type = ? WHERE question_type_id = ?', [question_type, id]);
  return result.affectedRows > 0;
};

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

module.exports = {
  getAllQuestionTypes,
  getQuestionTypeById,
  createQuestionType,
  updateQuestionType,
  deleteQuestionType
};

