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

// src/hooks/api/exchanges.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var EXCHANGES_QUERY_KEY = "exchanges";
var exchangesQueryKeys = queryKeysFactory(EXCHANGES_QUERY_KEY);
var invalidateOrder = (orderId) => {
  queryClient.invalidateQueries({ queryKey: ordersQueryKeys.details() });
  queryClient.invalidateQueries({ queryKey: ordersQueryKeys.preview(orderId) });
  queryClient.invalidateQueries({ queryKey: ordersQueryKeys.changes(orderId) });
  queryClient.invalidateQueries({ queryKey: exchangesQueryKeys.lists() });
};
var useExchanges = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: async () => sdk.vendor.exchanges.query({ ...query }),
    queryKey: exchangesQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateExchange = (orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.exchanges.mutate(payload),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCancelExchangeBegin = (exchangeId, orderId, options) => {
  return useMutation({
    mutationFn: () => sdk.vendor.exchanges.$id.request.delete({ $id: exchangeId }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRequestExchange = (exchangeId, orderId, options) => {
  return useMutation({
    mutationFn: () => sdk.vendor.exchanges.$id.request.mutate({ $id: exchangeId }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddExchangeInboundItems = (exchangeId, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.exchanges.$id.inbound.items.mutate({
      $id: exchangeId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateExchangeInboundItem = (exchangeId, orderId, options) => {
  return useMutation({
    mutationFn: ({ $actionId, ...payload }) => sdk.vendor.exchanges.$id.inbound.items.$actionId.mutate({
      $id: exchangeId,
      $actionId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRemoveExchangeInboundItem = (exchangeId, orderId, options) => {
  return useMutation({
    mutationFn: (actionId) => sdk.vendor.exchanges.$id.inbound.items.$actionId.delete({
      $id: exchangeId,
      $actionId: actionId
    }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddExchangeOutboundItems = (exchangeId, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.exchanges.$id.outbound.items.mutate({
      $id: exchangeId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateExchangeOutboundItem = (exchangeId, orderId, options) => {
  return useMutation({
    mutationFn: ({ $actionId, ...payload }) => sdk.vendor.exchanges.$id.outbound.items.$actionId.mutate({
      $id: exchangeId,
      $actionId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRemoveExchangeOutboundItem = (exchangeId, orderId, options) => {
  return useMutation({
    mutationFn: (actionId) => sdk.vendor.exchanges.$id.outbound.items.$actionId.delete({
      $id: exchangeId,
      $actionId: actionId
    }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddExchangeInboundShipping = (exchangeId, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.exchanges.$id.inbound.shippingMethod.mutate({
      $id: exchangeId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddExchangeOutboundShipping = (exchangeId, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.exchanges.$id.outbound.shippingMethod.mutate({
      $id: exchangeId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  useExchanges,
  useCreateExchange,
  useCancelExchangeBegin,
  useRequestExchange,
  useAddExchangeInboundItems,
  useUpdateExchangeInboundItem,
  useRemoveExchangeInboundItem,
  useAddExchangeOutboundItems,
  useUpdateExchangeOutboundItem,
  useRemoveExchangeOutboundItem,
  useAddExchangeInboundShipping,
  useAddExchangeOutboundShipping
};
