const adminBotService = require("../../services/admin/botService");
const ApiResponse = require("../../utils/apiResponse");
const { asyncHandler } = require("../../middleware/errorHandler");

exports.getBots = asyncHandler(async (req, res) => {
  const data = await adminBotService.getBots(req.query);
  ApiResponse.success(res, data);
});

exports.getBotById = asyncHandler(async (req, res) => {
  const { botId } = req.params;
  const data = await adminBotService.getBotById(botId);
  ApiResponse.success(res, data);
});

exports.createBot = asyncHandler(async (req, res) => {
  const bot = await adminBotService.createBot(req.body, req.admin?.id);
  ApiResponse.success(res, { bot }, "Bot created successfully");
});

exports.updateBot = asyncHandler(async (req, res) => {
  const { botId } = req.params;
  const bot = await adminBotService.updateBot(botId, req.body, req.admin?.id);
  ApiResponse.success(res, { bot }, "Bot updated successfully");
});

exports.deleteBot = asyncHandler(async (req, res) => {
  const { botId } = req.params;
  const result = await adminBotService.deleteBot(botId, req.admin?.id);
  ApiResponse.success(res, result, "Bot deleted successfully");
});

exports.updateBotStatus = asyncHandler(async (req, res) => {
  const { botId } = req.params;
  const { status } = req.body;
  const bot = await adminBotService.updateBotStatus(botId, status, req.admin?.id);
  ApiResponse.success(res, { bot }, "Bot status updated");
});