const supportFunction = require("../function/support");

const addSupport = async (req, res) => {
    try {
        const result = await supportFunction.addSupport(req);
        return res.status(200).json({
            success: true,
            msg: "Support Message is Added!",
            data: result
        })
    } catch (error) {
        console.log("Having Errors :", error);
        return res.status(400).json({
            success: false,
            msg: "Having Errors!",
            error: error.message
        })
    }
};

const getAllSupport = async (req, res) => {
    try {
        const result = await supportFunction.getAllSupportMessages(req);
        return res.status(200).json({
            success: true,
            msg: "All Support Messages!",
            data: result
        })
    } catch (error) {
        console.log("Having Errors :", error);
        return res.status(400).json({
            success: false,
            msg: "Having Errors!",
            error: error.message
        })
    }    
};

const getSupportById = async (req, res) => {
    try {
        const result = await supportFunction.getSupportById(req);
        console.log("Controller :", result)
        return res.status(200).json({
            success: true,
            msg: "Support Message Details!",
            data: result
        })
    } catch (error) {
        console.log("Having Errors :", error);
        return res.status(400).json({
            success: false,
            msg: "Having Errors!",
            error: error.message
        })
    }
};

const deleteSupport = async (req, res) => {
    try {
        const result = await supportFunction.deleteSupport(req);
        return res.status(200).json({
            success: true,
            msg: "Support Message is Deleted!",
        })
    } catch (error) {
        console.log("Having Errors :", error);
        return res.status(400).json({
            success: false,
            msg: "Having Errors!",
            error: error.message
        })
    }    
};

module.exports = {
    addSupport,
    getAllSupport,
    getSupportById,
    deleteSupport
}