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

// src/hooks/api/commission-rates.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var COMMISSION_RATES_QUERY_KEY = "commission_rates";
var commissionRatesQueryKeys = queryKeysFactory(
  COMMISSION_RATES_QUERY_KEY
);
var useCommissionRate = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.commissionRates.$id.query({ $id: id, ...query }),
    queryKey: commissionRatesQueryKeys.detail(id),
    ...options
  });
  return { ...data, ...rest };
};
var useCommissionRates = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.commissionRates.query({ ...query }),
    queryKey: commissionRatesQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateCommissionRate = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.commissionRates.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: commissionRatesQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateCommissionRate = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.commissionRates.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: commissionRatesQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: commissionRatesQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteCommissionRate = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.commissionRates.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: commissionRatesQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: commissionRatesQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useBatchCommissionRules = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.commissionRates.$id.rules.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: commissionRatesQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: commissionRatesQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  commissionRatesQueryKeys,
  useCommissionRate,
  useCommissionRates,
  useCreateCommissionRate,
  useUpdateCommissionRate,
  useDeleteCommissionRate,
  useBatchCommissionRules
};
