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

// src/hooks/api/inventory.tsx
import {
  useMutation as useMutation2,
  useQuery as useQuery2
} from "@tanstack/react-query";

// src/hooks/api/products.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var PRODUCTS_QUERY_KEY = "products";
var productsQueryKeys = queryKeysFactory(PRODUCTS_QUERY_KEY);
var VARIANTS_QUERY_KEY = "product_variants";
var variantsQueryKeys = queryKeysFactory(VARIANTS_QUERY_KEY);
var OPTIONS_QUERY_KEY = "product_options";
var optionsQueryKeys = queryKeysFactory(OPTIONS_QUERY_KEY);
var useCreateProductOption = (productId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.products.$id.options.mutate({ $id: productId, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: optionsQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.detail(productId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateProductOption = (productId, optionId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.products.$id.options.$optionId.mutate({
      $id: productId,
      $optionId: optionId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: optionsQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: optionsQueryKeys.detail(optionId)
      });
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.detail(productId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteProductOption = (productId, optionId, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.products.$id.options.$optionId.delete({
      $id: productId,
      $optionId: optionId
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: optionsQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: optionsQueryKeys.detail(optionId)
      });
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.detail(productId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useProductVariant = (productId, variantId, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.products.$id.variants.$variantId.query({
      $id: productId,
      $variantId: variantId,
      ...query
    }),
    queryKey: variantsQueryKeys.detail(variantId, query),
    ...options
  });
  return { ...data, ...rest };
};
var useProductVariants = (productId, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.products.$id.variants.query({ $id: productId, ...query }),
    queryKey: variantsQueryKeys.list({ productId, ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateProductVariant = (productId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.products.$id.variants.mutate({ $id: productId, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.detail(productId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateProductVariant = (productId, variantId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.products.$id.variants.$variantId.mutate({
      $id: productId,
      $variantId: variantId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: variantsQueryKeys.detail(variantId)
      });
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.detail(productId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateProductVariantsBatch = (productId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.products.$id.variants.batch.mutate({
      $id: productId,
      update: payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: variantsQueryKeys.details() });
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.detail(productId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useProductVariantsInventoryItemsBatch = (productId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.products.$id.variants.inventoryItems.batch.mutate({
      $id: productId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: variantsQueryKeys.details() });
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.detail(productId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteVariant = (productId, variantId, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.products.$id.variants.$variantId.delete({
      $id: productId,
      $variantId: variantId
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: variantsQueryKeys.detail(variantId)
      });
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.detail(productId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteVariantLazy = (productId, options) => {
  return useMutation({
    mutationFn: ({ variantId }) => sdk.admin.products.$id.variants.$variantId.delete({
      $id: productId,
      $variantId: variantId
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: variantsQueryKeys.detail(variables.variantId)
      });
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.detail(productId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useProduct = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.products.$id.query({ $id: id, ...query }),
    queryKey: productsQueryKeys.detail(id, query),
    ...options
  });
  return { ...data, ...rest };
};
var useProducts = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.products.query({ ...query }),
    queryKey: productsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateProduct = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.products.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateProduct = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.products.$id.mutate({ $id: id, ...payload }),
    onSuccess: async (data, variables, context) => {
      await queryClient.invalidateQueries({
        queryKey: productsQueryKeys.lists()
      });
      await queryClient.invalidateQueries({
        queryKey: productsQueryKeys.detail(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteProduct = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.products.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: productsQueryKeys.detail(id) });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useExportProducts = (query, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.products.export.mutate(payload),
    onSuccess: (data, variables, context) => {
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useImportProducts = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.products.import.mutate(payload),
    onSuccess: (data, variables, context) => {
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useConfirmImportProducts = (options) => {
  return useMutation({
    mutationFn: (transactionId) => sdk.admin.products.import.$transactionId.confirm.mutate({
      $transactionId: transactionId
    }),
    onSuccess: (data, variables, context) => {
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

// src/hooks/api/inventory.tsx
var INVENTORY_ITEMS_QUERY_KEY = "inventory_items";
var inventoryItemsQueryKeys = queryKeysFactory(
  INVENTORY_ITEMS_QUERY_KEY
);
var INVENTORY_ITEM_LEVELS_QUERY_KEY = "inventory_item_levels";
var inventoryItemLevelsQueryKeys = queryKeysFactory(
  INVENTORY_ITEM_LEVELS_QUERY_KEY
);
var useInventoryItems = (query, options) => {
  const { data, ...rest } = useQuery2({
    queryFn: () => sdk.admin.inventoryItems.query({ ...query }),
    queryKey: inventoryItemsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useInventoryItem = (id, query, options) => {
  const { data, ...rest } = useQuery2({
    queryFn: () => sdk.admin.inventoryItems.$id.query({ $id: id, ...query }),
    queryKey: inventoryItemsQueryKeys.detail(id),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateInventoryItem = (options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.admin.inventoryItems.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateInventoryItem = (id, options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.admin.inventoryItems.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.detail(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteInventoryItem = (id, options) => {
  return useMutation2({
    mutationFn: () => sdk.admin.inventoryItems.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.detail(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useInventoryItemLevels = (inventoryItemId, query, options) => {
  const { data, ...rest } = useQuery2({
    queryFn: () => sdk.admin.inventoryItems.$id.locationLevels.query({
      $id: inventoryItemId,
      ...query
    }),
    queryKey: inventoryItemLevelsQueryKeys.list({
      ...query || {},
      inventoryItemId
    }),
    ...options
  });
  return { ...data, ...rest };
};
var useUpdateInventoryLevel = (inventoryItemId, locationId, options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.admin.inventoryItems.$id.locationLevels.$locationId.mutate({
      $id: inventoryItemId,
      $locationId: locationId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.detail(inventoryItemId)
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemLevelsQueryKeys.detail(inventoryItemId)
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemLevelsQueryKeys.list({ inventoryItemId })
      });
      queryClient.invalidateQueries({
        queryKey: variantsQueryKeys.details()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useBatchInventoryItemLocationLevels = (inventoryItemId, options) => {
  return useMutation2({
    mutationFn: (payload) => {
      return sdk.admin.inventoryItems.$id.locationLevels.batch.mutate({
        $id: inventoryItemId,
        ...payload,
        // force: true is required for admin batch endpoint to delete levels with stocked items
        force: !!payload?.delete?.length || payload.force
      });
    },
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.detail(inventoryItemId)
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemLevelsQueryKeys.detail(inventoryItemId)
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemLevelsQueryKeys.list({ inventoryItemId })
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useBatchInventoryItemsLocationLevels = (options) => {
  return useMutation2({
    mutationFn: (payload) => {
      return sdk.admin.inventoryItems.locationLevels.batch.mutate({
        ...payload,
        // force: true is required for admin batch endpoint to delete levels with stocked items
        force: !!payload?.delete?.length || payload.force
      });
    },
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.all
      });
      queryClient.invalidateQueries({
        queryKey: variantsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  inventoryItemsQueryKeys,
  inventoryItemLevelsQueryKeys,
  useInventoryItems,
  useInventoryItem,
  useCreateInventoryItem,
  useUpdateInventoryItem,
  useDeleteInventoryItem,
  useInventoryItemLevels,
  useUpdateInventoryLevel,
  useBatchInventoryItemLocationLevels,
  useBatchInventoryItemsLocationLevels,
  productsQueryKeys,
  variantsQueryKeys,
  useCreateProductOption,
  useUpdateProductOption,
  useDeleteProductOption,
  useProductVariant,
  useProductVariants,
  useCreateProductVariant,
  useUpdateProductVariant,
  useUpdateProductVariantsBatch,
  useProductVariantsInventoryItemsBatch,
  useDeleteVariant,
  useDeleteVariantLazy,
  useProduct,
  useProducts,
  useCreateProduct,
  useUpdateProduct,
  useDeleteProduct,
  useExportProducts,
  useImportProducts,
  useConfirmImportProducts
};
