import {
  customerGroupsQueryKeys
} from "./chunk-PRBE5CM3.js";
import {
  productsQueryKeys
} from "./chunk-5CK6XEFV.js";
import {
  queryClient
} from "./chunk-RHKRREUU.js";
import {
  queryKeysFactory
} from "./chunk-ZA2KFUFR.js";
import {
  sdk
} from "./chunk-ZBWL72TB.js";

// src/hooks/api/price-lists.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var PRICE_LISTS_QUERY_KEY = "price-lists";
var priceListsQueryKeys = queryKeysFactory(PRICE_LISTS_QUERY_KEY);
var usePriceList = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.priceLists.$id.query({ $id: id, ...query }),
    queryKey: priceListsQueryKeys.detail(id),
    ...options
  });
  return { ...data, ...rest };
};
var usePriceLists = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.priceLists.query({ ...query }),
    queryKey: priceListsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreatePriceList = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.priceLists.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: priceListsQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: customerGroupsQueryKeys.all });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdatePriceList = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.priceLists.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: priceListsQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: priceListsQueryKeys.details()
      });
      queryClient.invalidateQueries({ queryKey: customerGroupsQueryKeys.all });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeletePriceList = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.priceLists.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: priceListsQueryKeys.lists() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useBatchPriceListPrices = (id, query, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.priceLists.$id.prices.batch.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: priceListsQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var usePriceListLinkProducts = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.priceLists.$id.products.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: priceListsQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({ queryKey: priceListsQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  priceListsQueryKeys,
  usePriceList,
  usePriceLists,
  useCreatePriceList,
  useUpdatePriceList,
  useDeletePriceList,
  useBatchPriceListPrices,
  usePriceListLinkProducts
};
