import { trpc } from "~/lib/trpc/client.js";

/** Invalidates just the 4 timeline queries */
export function useInvalidateTimeline() {
  const utils = trpc.useUtils();
  return () => {
    void utils.timeline.getEntries.invalidate();
    void utils.timeline.getEntriesView.invalidate();
    void utils.timeline.getMyEntriesView.invalidate();
    void utils.timeline.getHolidayOverlays.invalidate();
    void utils.timeline.getMyHolidayOverlays.invalidate();
    void utils.vacation.list.invalidate();
    void utils.timeline.getProjectContext.invalidate();
    void utils.timeline.getBudgetStatus.invalidate();
  };
}

/** Invalidates all 8 planning-related queries (4 timeline + 4 allocation) */
export function useInvalidatePlanningViews() {
  const utils = trpc.useUtils();
  return () => {
    void utils.allocation.list.invalidate();
    void (
      utils as {
        allocation: { listView: { invalidate: () => Promise<unknown> } };
      }
    ).allocation.listView.invalidate();
    void utils.allocation.listDemands.invalidate();
    void utils.allocation.listAssignments.invalidate();
    void utils.timeline.getEntries.invalidate();
    void utils.timeline.getEntriesView.invalidate();
    void utils.timeline.getMyEntriesView.invalidate();
    void utils.timeline.getHolidayOverlays.invalidate();
    void utils.timeline.getMyHolidayOverlays.invalidate();
    void utils.vacation.list.invalidate();
    void utils.timeline.getProjectContext.invalidate();
    void utils.timeline.getBudgetStatus.invalidate();
  };
}
