import { ShiftProjectSchema } from "@capakraken/shared";
import { z } from "zod";
import { controllerProcedure } from "../trpc.js";
import { previewTimelineProjectShift } from "./timeline-project-load-support.js";
import {
  readTimelineProjectBudgetStatusResponse,
  readTimelineProjectContextDetailResponse,
  readTimelineProjectContextResponse,
  readTimelineProjectShiftPreviewDetail,
} from "./timeline-project-procedure-support.js";

export const timelineProjectReadProcedures = {
  getProjectContext: controllerProcedure
    .input(z.object({ projectId: z.string() }))
    .query(async ({ ctx, input }) => readTimelineProjectContextResponse(ctx.db, input.projectId)),

  getProjectContextDetail: controllerProcedure
    .input(
      z.object({
        projectId: z.string(),
        startDate: z.string().optional(),
        endDate: z.string().optional(),
        durationDays: z.number().int().min(1).max(366).optional(),
      }),
    )
    .query(async ({ ctx, input }) => readTimelineProjectContextDetailResponse(ctx.db, input)),

  previewShift: controllerProcedure
    .input(ShiftProjectSchema)
    .query(async ({ ctx, input }) => previewTimelineProjectShift(ctx.db, input)),

  getShiftPreviewDetail: controllerProcedure
    .input(ShiftProjectSchema)
    .query(async ({ ctx, input }) => readTimelineProjectShiftPreviewDetail(ctx.db, input)),

  getBudgetStatus: controllerProcedure
    .input(z.object({ projectId: z.string() }))
    .query(async ({ ctx, input }) => readTimelineProjectBudgetStatusResponse(ctx.db, input.projectId)),
};
