// an external way to creating logs
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { apiHit } from "../../../globalUtils/apiHits.js";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
import hasCorrectRole from "../../auth/middleware/roleCheck.js";
import { getAllJobs } from "../utils/processNotifications.js";

const app = new OpenAPIHono({ strict: false });

app.openapi(
	createRoute({
		tags: ["server"],
		summary: "Returns current active notifications.",
		method: "get",
		path: "/activenotifications",
		middleware: [authMiddleware, hasCorrectRole(["systemAdmin"], "admin")],
		responses: responses(),
	}),
	async (c) => {
		apiHit(c, { endpoint: "/activenotifications" });
		const jobs = getAllJobs();
		return c.json({
			success: true,
			message:
				jobs.length === 0
					? "There are no active Notifications Currently."
					: "Current Active notifications",
			data: jobs,
		});
	},
);
export default app;
