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

// src/hooks/api/sales-channels.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var SALES_CHANNELS_QUERY_KEY = "sales-channels";
var salesChannelsQueryKeys = queryKeysFactory(SALES_CHANNELS_QUERY_KEY);
var useSalesChannel = (id, options) => {
  const { data, ...rest } = useQuery({
    queryKey: salesChannelsQueryKeys.detail(id),
    queryFn: () => sdk.admin.salesChannels.$id.query({ $id: id }),
    ...options
  });
  return { ...data, ...rest };
};
var useSalesChannels = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.salesChannels.query({ ...query }),
    queryKey: salesChannelsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateSalesChannel = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.salesChannels.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: salesChannelsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateSalesChannel = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.salesChannels.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: salesChannelsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: salesChannelsQueryKeys.detail(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteSalesChannel = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.salesChannels.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: salesChannelsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: salesChannelsQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.all
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteSalesChannelLazy = (options) => {
  return useMutation({
    mutationFn: (id) => sdk.admin.salesChannels.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: salesChannelsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: salesChannelsQueryKeys.detail(variables)
      });
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.all
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useSalesChannelRemoveProducts = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.salesChannels.$id.products.mutate({
      $id: id,
      remove: payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: salesChannelsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: salesChannelsQueryKeys.detail(id)
      });
      for (const product of variables || []) {
        queryClient.invalidateQueries({
          queryKey: productsQueryKeys.detail(product)
        });
      }
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useSalesChannelAddProducts = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.salesChannels.$id.products.mutate({
      $id: id,
      add: payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: salesChannelsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: salesChannelsQueryKeys.detail(id)
      });
      for (const product of variables || []) {
        queryClient.invalidateQueries({
          queryKey: productsQueryKeys.detail(product)
        });
      }
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  salesChannelsQueryKeys,
  useSalesChannel,
  useSalesChannels,
  useCreateSalesChannel,
  useUpdateSalesChannel,
  useDeleteSalesChannel,
  useDeleteSalesChannelLazy,
  useSalesChannelRemoveProducts,
  useSalesChannelAddProducts
};
