import {
  customerGroupsQueryKeys
} from "./chunk-II3CLUXA.js";
import {
  productsQueryKeys
} from "./chunk-YAUGB4LD.js";
import {
  queryClient
} from "./chunk-RHKRREUU.js";
import {
  queryKeysFactory
} from "./chunk-ZA2KFUFR.js";
import {
  sdk
} from "./chunk-DTGEFKK4.js";

// src/hooks/api/price-lists.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var PRICE_LISTS_QUERY_KEY = "price-lists";
var PRICE_LIST_PRICES_QUERY_KEY = "price-list-prices";
var priceListsQueryKeys = queryKeysFactory(PRICE_LISTS_QUERY_KEY);
var priceListPricesQueryKeys = queryKeysFactory(
  PRICE_LIST_PRICES_QUERY_KEY
);
var usePriceList = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.vendor.priceLists.$id.query({ $id: id, ...query }),
    queryKey: priceListsQueryKeys.detail(id, query),
    ...options
  });
  return { ...data, ...rest };
};
var usePriceLists = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.vendor.priceLists.query({ ...query }),
    queryKey: priceListsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreatePriceList = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.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.vendor.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.vendor.priceLists.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: priceListsQueryKeys.lists() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useBatchPriceListPrices = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.priceLists.$id.prices.batch.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: priceListsQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: priceListPricesQueryKeys.detail(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var usePriceListLinkProducts = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.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
  });
};
var usePriceListProducts = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.vendor.products.query({ price_list_id: [id], ...query }),
    queryKey: [PRICE_LISTS_QUERY_KEY, id, "products"],
    ...options
  });
  return { ...data, ...rest };
};

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