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

// src/hooks/api/return-reasons.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var RETURN_REASONS_QUERY_KEY = "return_reasons";
var returnReasonsQueryKeys = queryKeysFactory(RETURN_REASONS_QUERY_KEY);
var useReturnReasons = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.vendor.returnReasons.query({ ...query }),
    queryKey: returnReasonsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useReturnReason = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.vendor.returnReasons.$id.query({ $id: id, ...query }),
    queryKey: returnReasonsQueryKeys.detail(id),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateReturnReason = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.returnReasons.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: returnReasonsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateReturnReason = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.returnReasons.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: returnReasonsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: returnReasonsQueryKeys.detail(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteReturnReason = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.vendor.returnReasons.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: returnReasonsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: returnReasonsQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: returnReasonsQueryKeys.details()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  useReturnReasons,
  useReturnReason,
  useCreateReturnReason,
  useUpdateReturnReason,
  useDeleteReturnReason
};
