import { registry } from "../../infrastructure/openapi/registry";
import { z } from "zod";
import { ErrorResponseSchema } from "../../infrastructure/openapi/security";

const ManagerDashboardResponseSchema = registry.register(
  "ManagerDashboardResponse",
  z.object({
    success: z.boolean().default(true),
    statusCode: z.number().default(200),
    message: z.string().optional(),
    data: z.any().optional(),
  }),
);

registry.registerPath({
  method: "get",
  path: "/manager/tasks/stats",
  summary: "Get task statistics for the logged-in manager (Manager/Admin only)",
  tags: ["Manager Dashboard"],
  security: [{ bearerAuth: [] }],
  responses: {
    200: {
      description: "Task stats fetched successfully",
      content: {
        "application/json": { schema: ManagerDashboardResponseSchema },
      },
    },
    400: {
      description: "Manager profile not found or access denied",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
    401: {
      description: "Unauthorized",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
  },
});

registry.registerPath({
  method: "get",
  path: "/manager/tasks/trend",
  summary:
    "Get approval/rejection decision trend for the logged-in manager (Manager/Admin only)",
  tags: ["Manager Dashboard"],
  security: [{ bearerAuth: [] }],
  request: {
    query: z.object({
      days: z
        .string()
        .optional()
        .describe("Number of days to include in the trend (default: 30)"),
    }),
  },
  responses: {
    200: {
      description: "Decision trend fetched successfully",
      content: {
        "application/json": { schema: ManagerDashboardResponseSchema },
      },
    },
    400: {
      description: "Manager profile not found or access denied",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
    401: {
      description: "Unauthorized",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
  },
});

registry.registerPath({
  method: "get",
  path: "/manager/team-performance",
  summary:
    "Get completed-task counts per employee under the manager (Manager/Admin only)",
  tags: ["Manager Dashboard"],
  security: [{ bearerAuth: [] }],
  responses: {
    200: {
      description: "Team performance fetched successfully",
      content: {
        "application/json": { schema: ManagerDashboardResponseSchema },
      },
    },
    400: {
      description: "Manager profile not found or access denied",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
    401: {
      description: "Unauthorized",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
  },
});
