import { registry } from "../../infrastructure/openapi/registry";
import { z } from "zod";
import { ErrorResponseSchema } from "../../infrastructure/openapi/security";

const DashboardStatsSchema = registry.register(
  "AdminDashboardStats",
  z.object({
    success: z.boolean(),
    data: z.object({
      cards: z.object({
        totalClients: z.number(),
        totalEmployees: z.number(),
        totalManagers: z.number(),
        totalTasks: z.number(),
        pendingTasks: z.number(),
        completedTasks: z.number(),
      }),
      taskStatusGraph: z.array(
        z.object({ status: z.string(), count: z.number() })
      ),
      departmentTaskGraph: z.array(
        z.object({ department: z.string(), tasks: z.number() })
      ),
      clientStatusGraph: z.array(
        z.object({ status: z.string(), count: z.number() })
      ),
    }),
    message: z.string(),
  })
);

registry.registerPath({
  method: "get",
  path: "/admin-dashboard/stats",
  summary: "Get admin dashboard stats (cards + graphs)",
  tags: ["Admin Dashboard"],
  security: [{ bearerAuth: [] }],
  responses: {
    200: {
      description: "Dashboard stats fetched successfully",
      content: { "application/json": { schema: DashboardStatsSchema } },
    },
    401: {
      description: "Unauthorized",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
    403: {
      description: "Forbidden",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
  },
});
