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

// src/hooks/api/product-types.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var PRODUCT_TYPES_QUERY_KEY = "product_types";
var productTypesQueryKeys = queryKeysFactory(PRODUCT_TYPES_QUERY_KEY);
var useProductType = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.vendor.productTypes.$id.query({ $id: id, ...query }),
    queryKey: productTypesQueryKeys.detail(id),
    ...options
  });
  return { ...data, ...rest };
};
var useProductTypes = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.vendor.productTypes.query({ ...query }),
    queryKey: productTypesQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useUpdateProductType = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.productTypes.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: productTypesQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: productTypesQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteProductType = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.vendor.productTypes.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: productTypesQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: productTypesQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  productTypesQueryKeys,
  useProductType,
  useProductTypes,
  useUpdateProductType,
  useDeleteProductType
};
