/**
 * Admin home content controller
 */

const adminHomeService = require('../services/adminHomeService');
const { sendSuccess } = require('../utils/response');

// ============ Banner Controllers ============

exports.getBanners = async (req, res, next) => {
  try {
    const banners = await adminHomeService.getAllBanners();
    return sendSuccess(res, banners, 'Banners retrieved successfully');
  } catch (error) {
    next(error);
  }
};

exports.createBanner = async (req, res, next) => {
  try {
    const banner = await adminHomeService.createBanner(req.body);
    return sendSuccess(res, banner, 'Banner created successfully', 201);
  } catch (error) {
    next(error);
  }
};

exports.updateBanner = async (req, res, next) => {
  try {
    const banner = await adminHomeService.updateBanner(req.params.id, req.body);
    return sendSuccess(res, banner, 'Banner updated successfully');
  } catch (error) {
    next(error);
  }
};

exports.deleteBanner = async (req, res, next) => {
  try {
    await adminHomeService.deleteBanner(req.params.id);
    return sendSuccess(res, null, 'Banner deleted successfully');
  } catch (error) {
    next(error);
  }
};

// ============ Hot Service Controllers ============

exports.getHotServices = async (req, res, next) => {
  try {
    const services = await adminHomeService.getAllHotServices();
    return sendSuccess(res, services, 'Hot services retrieved successfully');
  } catch (error) {
    next(error);
  }
};

exports.createHotService = async (req, res, next) => {
  try {
    const service = await adminHomeService.createHotService(req.body);
    return sendSuccess(res, service, 'Hot service created successfully', 201);
  } catch (error) {
    next(error);
  }
};

exports.updateHotService = async (req, res, next) => {
  try {
    const service = await adminHomeService.updateHotService(req.params.id, req.body);
    return sendSuccess(res, service, 'Hot service updated successfully');
  } catch (error) {
    next(error);
  }
};

exports.deleteHotService = async (req, res, next) => {
  try {
    await adminHomeService.deleteHotService(req.params.id);
    return sendSuccess(res, null, 'Hot service deleted successfully');
  } catch (error) {
    next(error);
  }
};
