import Payment from "../models/Payment.js";
 
export const createPayment = async (req, res) => {
    try {
        const payment = await Payment.create(req.body);
        res.status(201).json(payment);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
};
 
export const getPayment = async (req, res) => {
    try {
        const payments = await Payment.find()
            .populate({
                path: "serviceRecord",
                populate: [
                    { path: "car" },
                    { path: "service" }
                ]
            });
        res.status(200).json(payments);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
};
 
export const updatePayment = async (req, res) => {
    try {
        const payment = await Payment.findByIdAndUpdate(req.params.id, req.body, { new: true });
        res.status(200).json(payment);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
};
 
export const deletePayment = async (req, res) => {
    try {
        const payment = await Payment.findByIdAndDelete(req.params.id);
        res.status(200).json(payment);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
};