import {
  taxRegionsQueryKeys
} from "./chunk-VME3CJER.js";
import {
  queryClient
} from "./chunk-RHKRREUU.js";
import {
  queryKeysFactory
} from "./chunk-ZA2KFUFR.js";
import {
  sdk
} from "./chunk-RIN4CBRB.js";

// src/hooks/api/tax-rates.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var TAX_RATES_QUERY_KEY = "tax_rates";
var taxRatesQueryKeys = queryKeysFactory(TAX_RATES_QUERY_KEY);
var useTaxRate = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryKey: taxRatesQueryKeys.detail(id),
    queryFn: async () => sdk.admin.taxRates.$id.query({ $id: id, ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useTaxRates = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.taxRates.query({ ...query }),
    queryKey: taxRatesQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useUpdateTaxRate = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.taxRates.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: taxRatesQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: taxRatesQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({ queryKey: taxRegionsQueryKeys.details() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCreateTaxRate = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.taxRates.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: taxRatesQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: taxRegionsQueryKeys.details() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteTaxRate = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.taxRates.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: taxRatesQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: taxRatesQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({ queryKey: taxRegionsQueryKeys.details() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  useTaxRate,
  useTaxRates,
  useUpdateTaxRate,
  useCreateTaxRate,
  useDeleteTaxRate
};
