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

exports.getMeetings = async (req, res) => {
  try {
    const meetings = await Meeting.find({ isDelete : false });
    const formattedMeetings = meetings.map((meeting) => {
      const formattedAgenda = meeting.agenda
        ? meeting.agenda.map((item, index) => `<li>${index + 1}. ${item}</li>`).join("")
        : "<li>No agenda provided</li>";
      return { ...meeting.toObject(), formattedAgenda };
    });

    res.json(formattedMeetings);
  } catch (error) {
    console.error("Error fetching meetings:", error);
    res.status(500).json({ error: "Error fetching meetings" });
  }
};
// ✅ Soft delete controller (NEW)
exports.softDeleteMeeting = async (req, res) => {
  try {
    const { id } = req.params;

    const meeting = await Meeting.findByIdAndUpdate(id, { isDeleted: true }, { new: true });

    if (!meeting) {
      return res.status(404).json({ error: "Meeting not found" });
    }

    res.json({ message: "Meeting soft deleted successfully", meeting });
  } catch (error) {
    console.error("Error soft deleting meeting:", error);
    res.status(500).json({ error: "Failed to soft delete meeting" });
  }
};
