const TblFuncionario = require("../models/TblFuncionarios");

const getAllUsers = async () => {
  return TblFuncionario.findAll();
};

const getUserById = async (id) => {
  return TblFuncionario.findByPk(id);
};

const createUser = async (userData) => {
  return TblFuncionario.create(userData);
};

const updateUser = async (id, userData) => {
  const user = await TblFuncionario.findByPk(id);
  if (!user) {
    throw new Error("User not found");
  }
  return user.update(userData);
};

const deleteUser = async (id) => {
  const user = await TblFuncionario.findByPk(id);
  if (!user) {
    throw new Error("User not found");
  }
  return user.destroy();
};

module.exports = {
  getAllUsers,
  getUserById,
  createUser,
  updateUser,
  deleteUser,
};
