import { PermissionKey, ShiftProjectSchema } from "@capakraken/shared";
import { managerProcedure, requirePermission } from "../trpc.js";
import { timelineAllocationMutationProcedures } from "./timeline-allocation-mutations.js";
import { applyTimelineProjectShiftMutation } from "./timeline-shift-router-support.js";

export const timelineMutationProcedures = {
  ...timelineAllocationMutationProcedures,

  applyShift: managerProcedure
    .input(ShiftProjectSchema)
    .mutation(async ({ ctx, input }) => {
      requirePermission(ctx, PermissionKey.MANAGE_ALLOCATIONS);

      return applyTimelineProjectShiftMutation({
        db: ctx.db,
        projectId: input.projectId,
        newStartDate: input.newStartDate,
        newEndDate: input.newEndDate,
      });
    }),
};
