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

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

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

const createFormsType = async (form_type_id, form_type) => {
  await pool.query('INSERT INTO sat_forms_type (form_type_id, form_type) VALUES (?, ?)', [form_type_id, form_type]);
};

const updateFormsType = async (id, form_type) => {
  const [result] = await pool.query('UPDATE sat_forms_type SET form_type = ? WHERE form_type_id = ?', [form_type, id]);
  return result.affectedRows > 0;
};

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

module.exports = {
  getAllFormsTypes,
  getFormsTypeById,
  createFormsType,
  updateFormsType,
  deleteFormsType
};

