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

// src/hooks/api/tax-regions.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var TAX_REGIONS_QUERY_KEY = "tax_regions";
var taxRegionsQueryKeys = queryKeysFactory(TAX_REGIONS_QUERY_KEY);
var useTaxRegion = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryKey: taxRegionsQueryKeys.detail(id),
    queryFn: () => sdk.admin.taxRegions.$id.query({ $id: id, ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useTaxRegions = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.taxRegions.query({ ...query }),
    queryKey: taxRegionsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateTaxRegion = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.taxRegions.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: taxRegionsQueryKeys.all });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateTaxRegion = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.taxRegions.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: taxRegionsQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({ queryKey: taxRegionsQueryKeys.lists() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteTaxRegion = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.taxRegions.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: taxRegionsQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: taxRegionsQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({ queryKey: taxRegionsQueryKeys.details() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  taxRegionsQueryKeys,
  useTaxRegion,
  useTaxRegions,
  useCreateTaxRegion,
  useUpdateTaxRegion,
  useDeleteTaxRegion
};
