import { Request, Response } from "express";
import { isValidObjectId } from "mongoose";
import Occasion from "../../models/occasion";

// Soft delete — keeps historical occasions referenced by past events intact,
// while removing it from the active list new events can pick from.
const deleteOccasion = async (req: Request, res: Response) => {
  const { id } = req.params;

  if (!isValidObjectId(id)) {
    return res.status(400).json({ message: "Occasion ID is not valid" });
  }

  try {
    const occasion = await Occasion.findById(id);
    if (!occasion) {
      return res.status(404).json({ message: "Occasion not found" });
    }

    occasion.isActive = false;
    await occasion.save();

    res.status(200).json({ message: "Occasion deactivated" });
  } catch (err) {
    res.status(500).json({ message: "Something went wrong", error: err });
  }
};

export { deleteOccasion };
