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

// src/hooks/api/shipping-options.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var SHIPPING_OPTIONS_QUERY_KEY = "shipping_options";
var shippingOptionsQueryKeys = queryKeysFactory(
  SHIPPING_OPTIONS_QUERY_KEY
);
var useShippingOption = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.shippingOptions.$id.query({ $id: id, ...query }),
    queryKey: shippingOptionsQueryKeys.detail(id),
    ...options
  });
  return { ...data, ...rest };
};
var useShippingOptions = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.shippingOptions.query({ ...query }),
    queryKey: shippingOptionsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateShippingOptions = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.shippingOptions.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: stockLocationsQueryKeys.all
      });
      queryClient.invalidateQueries({
        queryKey: shippingOptionsQueryKeys.all
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateShippingOptions = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.shippingOptions.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: stockLocationsQueryKeys.all
      });
      queryClient.invalidateQueries({
        queryKey: shippingOptionsQueryKeys.all
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteShippingOption = (optionId, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.shippingOptions.$id.delete({ $id: optionId }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: stockLocationsQueryKeys.all
      });
      queryClient.invalidateQueries({
        queryKey: shippingOptionsQueryKeys.all
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  shippingOptionsQueryKeys,
  useShippingOption,
  useShippingOptions,
  useCreateShippingOptions,
  useUpdateShippingOptions,
  useDeleteShippingOption
};
