const { query } = require("express");
const gestaoStockService = require("../services/gestaoStockService");
const logger = require("../utils/logger");

// Controller methods for user operations
const getStockMaquina = async (req, res) => {
  const queryParams = req.query; // Assuming you want to get parameters from the request body

  const maquinaId = req.params.id;

  try {
    const users = await gestaoStockService.getStockMaquina(maquinaId, queryParams);
    res.json(users);
  } catch (error) {
    console.log(error);
    logger.error(`Error getting all users: ${error.message}`);
    res.status(500).json({ error: "Internal Server Error" });
  }
};


const updateStockMaquina = async (req, res) => {
  try {
    const maquinaId = req.params.id;

  const queryParams = req.body.selectedRows;
 // Assuming you want to get parameters from the request body
  const userId = req.body.idUser;


    const user = await gestaoStockService.atualizaStockMaquina(maquinaId, userId, queryParams);
    if (!user) {
      return res.status(404).json({ success: false, error: "User not found" });
    }
    return res.status(200).json({success: true});
  } catch (error) {
    logger.error(`Error getting user by ID: ${error.message}`);
    res.status(500).json({ success: false, error: "Internal Server Error" });
  }
};




module.exports = {
  getStockMaquina,
  updateStockMaquina,
};
