const supportModel = require("../models/support");

const addSupport = async (req) => {
    const newSupport = new supportModel(req.body);
    const result = await newSupport.save();
    return result
};

const getAllSupportMessages = async (req) => {
    const result = await supportModel.find().populate({
        path: "userId",
        select: "-password"
    });
    return result
};

const getSupportById = async (req) => {
    const { supportId } = req.query;
    const result = await supportModel.findById({_id: supportId})
    .populate({
        path: "userId",
        select: "-password"
    });
    return result
};

const deleteSupport = async (req) => {
    const { supportId } = req.query;
    const result = await supportModel.findByIdAndDelete({_id: supportId});
    return result
};


module.exports = {
    addSupport,
    getAllSupportMessages,
    getSupportById,
    deleteSupport
};