const businessCatModel = require("../models/businessCategory");

const categoryExist = async (req) => {
    const {businessCatName} = req.body;
    const exist = await businessCatModel.findOne({
        businessCatName: { $regex: `^${businessCatName}$`, $options: 'i' }
    });
    return !!exist;
};

const addBusinessCategory = async (req) => {
    const newBusinessCategory = new businessCatModel(req.body);
    const result = await newBusinessCategory.save();
    return result
};

const getAllCategories = async (req) => {
    const result = await businessCatModel.find();
    return result
};

const deleteCategory = async (req) => {
    const { categoryId } = req.query;
    const result = await businessCatModel.findByIdAndDelete({_id: categoryId});
    return result
};

module.exports = {
    categoryExist,
    addBusinessCategory,
    getAllCategories,
    deleteCategory
};