import { Router } from "express";

import { prisma } from "@repo/db";
import { sendReportEmbed } from "modules/discord";

const router: Router = Router();

router.put("/", async (req, res) => {
	try {
		const report = await prisma.report.create({
			data: req.body,
		});
		sendReportEmbed(report.id).catch((error) => {
			console.error("Error sending report embed to Discord:", error);
		});

		res.json(report);
	} catch (error) {
		res.status(500).json({
			message: "Error creating report",
			error: error instanceof Error ? error.message : String(error),
		});
	}
});

export default router;
