/**
 * Admin dashboard HTTP surface.
 *
 *   GET /api/v1/admin/dashboard/stats — user + skill totals.
 *
 * The `/admin/dashboard/recent-activities` endpoint was removed in
 * issue #271 — the activity feed lives in PostHog now. The admin UI
 * deep-links to the PostHog dashboard for the same data.
 *
 * Gated on `ornn:admin:skill`.
 *
 * @module domains/admin/dashboard/routes
 */

import { Hono } from "hono";
import {
  type AuthVariables,
  nyxidAuthMiddleware,
  requirePermission,
} from "../../../middleware/nyxidAuth";
import { QUOTA_ADMIN_PERMISSION } from "../../quota/types";
import type { AdminDashboardService } from "./service";

export interface AdminDashboardRoutesConfig {
  dashboardService: AdminDashboardService;
}

export function createAdminDashboardRoutes(
  config: AdminDashboardRoutesConfig,
): Hono<{ Variables: AuthVariables }> {
  const { dashboardService } = config;
  const app = new Hono<{ Variables: AuthVariables }>();
  const auth = nyxidAuthMiddleware();

  app.get(
    "/admin/dashboard/stats",
    auth,
    requirePermission(QUOTA_ADMIN_PERMISSION),
    async (c) => {
      const stats = await dashboardService.getStats();
      return c.json({ data: stats, error: null });
    },
  );

  return app;
}
