import {
  queryClient
} from "./chunk-RHKRREUU.js";
import {
  queryKeysFactory
} from "./chunk-ZA2KFUFR.js";
import {
  sdk
} from "./chunk-RIN4CBRB.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.admin.productTypes.$id.query({ $id: id, ...query }),
    queryKey: productTypesQueryKeys.detail(id),
    ...options
  });
  return { ...data, ...rest };
};
var useProductTypes = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.productTypes.query({ ...query }),
    queryKey: productTypesQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateProductType = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.productTypes.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: productTypesQueryKeys.lists() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateProductType = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.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.admin.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,
  useCreateProductType,
  useUpdateProductType,
  useDeleteProductType
};
