import { Hono } from "hono";
import { withConsoleUserSession } from "@/middlewares/withConsoleUserSession";
import { WorkflowController } from "@/controllers/admin/workflows/workflows.controller";

export const WorkflowRoutes = new Hono();

// All workflow routes require a valid admin console user session
WorkflowRoutes.use("*", withConsoleUserSession());

WorkflowRoutes.get("/tasks", async (ctx) => WorkflowController(ctx).ListTasks());
WorkflowRoutes.get("/tasks/entity/:entityType/:entityId", async (ctx) => WorkflowController(ctx).GetTaskByEntity());
WorkflowRoutes.post("/tasks", async (ctx) => WorkflowController(ctx).UpsertTask());

// Open change requests for one or more targets — what the editor draws in the
// gutter. Declared before "/change-requests/:id/..." for clarity, not need.
WorkflowRoutes.get("/change-requests", async (ctx) => WorkflowController(ctx).ListChangeRequestsByTarget());

WorkflowRoutes.post("/tasks/:id/comments", async (ctx) => WorkflowController(ctx).AddComment());
WorkflowRoutes.post("/tasks/:id/change-requests", async (ctx) => WorkflowController(ctx).CreateChangeRequest());

WorkflowRoutes.put("/change-requests/:id/resolve", async (ctx) => WorkflowController(ctx).ResolveChangeRequest());

WorkflowRoutes.get("/notifications", async (ctx) => WorkflowController(ctx).GetNotifications());
WorkflowRoutes.put("/notifications/:id/read", async (ctx) => WorkflowController(ctx).MarkNotificationAsRead());
