const express = require("express");
const mongoose = require("mongoose");
const router = express.Router();

const Report = require("../models/Report");

router.get("/all", async (req, res) => {
  try {
    const reports = await Report.find()
      .populate("car")
      .populate('servicename')
      .populate("payment");

    res.json({
      message: "Reports fetched successfully",
      reports
    });
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
}); 

router.delete("/delete/:id", async (req, res) => {
  try {
    await Report.findByIdAndDelete(req.params.id);
    res.json({ message: "Report deleted" });
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
});

module.exports = router;