const categoryFunction = require("../function/category");

const addCaregory = async (req, res) => {
    try {
        const category = await categoryFunction.addCategory(req);
        return res.status(200).json({
            success: true,
            msg: "Category Added Successfully!",
            data: category
        })
    } catch (error) {
        console.log("Having Erros: ", error);
        return res.status(200).json({
            success: false,
            msg: "Having Errors",
            error: error.message
        })
    }
};

const getCategoryById = async (req, res) => {
    try {
        const category = await categoryFunction.getCategory(req);
        return res.status(200).json({
            success: true,
            msg: "Category By Id!",
            data: category
        })
    } catch (error) {
        console.log("Having Erros: ", error);
        return res.status(200).json({
            success: false,
            msg: "Having Errors",
            error: error.message
        })
    }
};

const getCategoriesByAdminId = async (req, res) => {
    try {
        const categories = await categoryFunction.getAllCategoriesByAdmin(req);
        return res.status(200).json({
            success: true,
            msg: "All Categories By Admin Id!",
            data: categories
        })
    } catch (error) {
        console.log("Having Erros: ", error);
        return res.status(200).json({
            success: false,
            msg: "Having Errors",
            error: error.message
        })
    }
};

const getAllCategories = async (req, res) => {
    try {
        const categories = await categoryFunction.getAllCategories(req);
        return res.status(200).json({
            success: true,
            msg: "All Categories!",
            data: categories
        })
    } catch (error) {
        console.log("Having Erros: ", error);
        return res.status(200).json({
            success: false,
            msg: "Having Errors",
            error: error.message
        })
    }
};

const deleteCategory = async (req, res) =>{
    try {
        const category = await categoryFunction.deleteCategory(req);
        return res.status(200).json({
            success: true,
            msg: "Category is Deleted Successfully!",
        });
    } catch (error) {
        console.log("Having Erros: ", error);
        return res.status(200).json({
            success: false,
            msg: "Having Errors",
            error: error.message
        })
    }
};

module.exports = {
    addCaregory,
    getCategoryById,
    getCategoriesByAdminId,
    getAllCategories,
    deleteCategory
};