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

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

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