"use client";

import { keepPreviousData, useQuery } from "@tanstack/react-query";

import { listProviderPackagesApi } from "@/lib/api/catalog.api";
import { queryKeys } from "@/lib/constants/query-keys";
import type { ProviderPackageListParams } from "@/types/catalog";

/**
 * The admin catalog as seen by the signed-in provider — every active package,
 * each flagged with whether this provider offers it and at what price.
 *
 * The provider is taken from the JWT backend-side, so nothing identifies it
 * here (and nothing should: the endpoint accepts no provider param).
 */
export function useProviderPackages(params: ProviderPackageListParams) {
  return useQuery({
    queryKey: queryKeys.catalog.providerList(params),
    queryFn: () => listProviderPackagesApi(params),
    placeholderData: keepPreviousData,
  });
}
