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

// src/hooks/api/shipping-profiles.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var SHIPPING_PROFILE_QUERY_KEY = "shipping_profile";
var shippingProfileQueryKeys = queryKeysFactory(
  SHIPPING_PROFILE_QUERY_KEY
);
var useCreateShippingProfile = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.shippingProfiles.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: shippingProfileQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useShippingProfile = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.shippingProfiles.$id.query({ $id: id, ...query }),
    queryKey: shippingProfileQueryKeys.detail(id, query),
    ...options
  });
  return { ...data, ...rest };
};
var useShippingProfiles = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.shippingProfiles.query({ ...query }),
    queryKey: shippingProfileQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useUpdateShippingProfile = (id, options) => {
  const { data, ...rest } = useMutation({
    mutationFn: (payload) => sdk.admin.shippingProfiles.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data2, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: shippingProfileQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: shippingProfileQueryKeys.lists()
      });
      options?.onSuccess?.(data2, variables, context);
    },
    ...options
  });
  return { ...data, ...rest };
};
var useDeleteShippingProfile = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.shippingProfiles.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: shippingProfileQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: shippingProfileQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  shippingProfileQueryKeys,
  useCreateShippingProfile,
  useShippingProfile,
  useShippingProfiles,
  useUpdateShippingProfile,
  useDeleteShippingProfile
};
