import {
  getEventSummaryHandler,
  getEventTypeAnalyticsHandler,
  getMemberAnalyticsHandler,
  getMemberDetailHandler,
  listEventRecordsHandler,
} from "@/controllers/admin/event-analytics/event-analytics.controller";
import { withConsoleUserRole } from "@/middlewares/console-role";
import { withConsoleUserSession } from "@/middlewares/withConsoleUserSession";
import { Hono } from "hono";

/**
 * Booking event analytics, read from the `event-tracking` Firestore database.
 *
 * Read-only by design: there is no write endpoint here and there should never
 * be one — the events are owned by the producing system.
 */
export const EventAnalyticsRoutes = new Hono();

EventAnalyticsRoutes.get(
  "/summary",
  withConsoleUserSession(),
  withConsoleUserRole("event-analytics", "read"),
  getEventSummaryHandler,
);

EventAnalyticsRoutes.get(
  "/members",
  withConsoleUserSession(),
  withConsoleUserRole("event-analytics", "read"),
  getMemberAnalyticsHandler,
);

// Registered before "/members" would ever shadow it — Hono matches the more
// specific path regardless of order, but keeping them adjacent makes the pair
// obvious.
EventAnalyticsRoutes.get(
  "/members/:memberId",
  withConsoleUserSession(),
  withConsoleUserRole("event-analytics", "read"),
  getMemberDetailHandler,
);

EventAnalyticsRoutes.get(
  "/events",
  withConsoleUserSession(),
  withConsoleUserRole("event-analytics", "read"),
  getEventTypeAnalyticsHandler,
);

EventAnalyticsRoutes.get(
  "/records",
  withConsoleUserSession(),
  withConsoleUserRole("event-analytics", "read"),
  listEventRecordsHandler,
);
