import type { QueryClient } from "@tanstack/react-query";

/** TanStack partial match invalidates every `["applications", …]` list query. */
export const APPLICATIONS_ROOT_QUERY_KEY = ["applications"] as const;

/**
 * After saving or deleting an admin adjudication result, refresh result detail, list filters,
 * and any cached application detail so **Kết quả đăng ký** stays aligned with Postgres.
 */
export async function invalidateAfterAdminApplicationResultChange(
  queryClient: QueryClient,
  applicationId: string,
): Promise<void> {
  const id = applicationId.trim();
  await queryClient.invalidateQueries({ queryKey: ["admin-application-result", id] });
  await queryClient.invalidateQueries({ queryKey: APPLICATIONS_ROOT_QUERY_KEY });
  await queryClient.invalidateQueries({ queryKey: ["application-detail", id] });
}
