import { prisma } from "../../config/prisma";
import { BadRequestError } from "../../common/errors/http-errors";
import * as taskRepo from "../client-dashborad/client.dashborad.repo";

async function getClientContext(userId: string) {
  const client = await prisma.client.findUnique({
    where: { userId },
    select: { id: true },
  });
  if (!client) throw new BadRequestError("Client profile not found");
  return client;
}

export async function getTaskStats(userId: string) {
  const client = await getClientContext(userId);
  return taskRepo.getTaskStatsByClient(client.id);
}

export async function getTaskTrend(userId: string, days?: number) {
  const client = await getClientContext(userId);
  return taskRepo.getTaskTrendByClient(client.id, days);
}
