import { prisma } from "../../config/prisma";
import { BadRequestError } from "../../common/errors/http-errors";
import * as employeeDashboardRepo from "./emp.dashobord.repo";

async function getEmployeeContext(userId: string) {
  const employee = await prisma.employee.findUnique({
    where: { userId },
    select: { id: true },
  });
  if (!employee) throw new BadRequestError("Employee profile not found");
  return employee;
}

export async function getTaskStats(userId: string) {
  const employee = await getEmployeeContext(userId);
  return employeeDashboardRepo.getTaskStatsByEmployee(employee.id);
}

export async function getTaskTrend(userId: string, days?: number) {
  const employee = await getEmployeeContext(userId);
  return employeeDashboardRepo.getTaskTrendByEmployee(employee.id, days);
}
