/**
 * Admin category controller
 */

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

/**
 * Get all categories
 */
exports.getCategories = async (req, res, next) => {
  try {
    const categories = await adminCategoryService.getAllCategories();
    return sendSuccess(res, categories, 'Categories retrieved successfully');
  } catch (error) {
    next(error);
  }
};

/**
 * Get category by ID
 */
exports.getCategoryById = async (req, res, next) => {
  try {
    const category = await adminCategoryService.getCategoryById(req.params.id);
    return sendSuccess(res, category, 'Category retrieved successfully');
  } catch (error) {
    next(error);
  }
};

/**
 * Create category
 */
exports.createCategory = async (req, res, next) => {
  try {
    const category = await adminCategoryService.createCategory(req.body);
    return sendSuccess(res, category, 'Category created successfully', 201);
  } catch (error) {
    next(error);
  }
};

/**
 * Update category
 */
exports.updateCategory = async (req, res, next) => {
  try {
    const category = await adminCategoryService.updateCategory(req.params.id, req.body);
    return sendSuccess(res, category, 'Category updated successfully');
  } catch (error) {
    next(error);
  }
};

/**
 * Delete category
 */
exports.deleteCategory = async (req, res, next) => {
  try {
    await adminCategoryService.deleteCategory(req.params.id);
    return sendSuccess(res, null, 'Category deleted successfully');
  } catch (error) {
    next(error);
  }
};
