import {
  returnsQueryKeys
} from "./chunk-BMC2HG53.js";
import {
  ordersQueryKeys
} from "./chunk-R74OHYTB.js";
import {
  queryClient
} from "./chunk-RHKRREUU.js";
import {
  queryKeysFactory
} from "./chunk-ZA2KFUFR.js";
import {
  sdk
} from "./chunk-RIN4CBRB.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 useExchange = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: async () => sdk.admin.exchanges.$id.query({ $id: id, ...query }),
    queryKey: exchangesQueryKeys.detail(id, query),
    ...options
  });
  return { ...data, ...rest };
};
var useExchanges = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: async () => sdk.admin.exchanges.query({ ...query }),
    queryKey: exchangesQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateExchange = (orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.exchanges.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      queryClient.invalidateQueries({
        queryKey: exchangesQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCancelExchange = (id, orderId, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.exchanges.$id.cancel.mutate({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      queryClient.invalidateQueries({
        queryKey: exchangesQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: exchangesQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddExchangeInboundItems = (id, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.exchanges.$id.inbound.items.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateExchangeInboundItem = (id, orderId, options) => {
  return useMutation({
    mutationFn: ({
      actionId,
      ...payload
    }) => {
      return sdk.admin.exchanges.$id.inbound.items.$actionId.mutate({
        $id: id,
        $actionId: actionId,
        ...payload
      });
    },
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRemoveExchangeInboundItem = (id, orderId, options) => {
  return useMutation({
    mutationFn: (actionId) => sdk.admin.exchanges.$id.inbound.items.$actionId.delete({
      $id: id,
      $actionId: actionId
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      queryClient.invalidateQueries({
        queryKey: returnsQueryKeys.details()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddExchangeInboundShipping = (id, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.exchanges.$id.inbound.shippingMethod.mutate({
      $id: id,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateExchangeInboundShipping = (id, orderId, options) => {
  return useMutation({
    mutationFn: ({
      actionId,
      ...payload
    }) => sdk.admin.exchanges.$id.inbound.shippingMethod.$actionId.mutate({
      $id: id,
      $actionId: actionId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteExchangeInboundShipping = (id, orderId, options) => {
  return useMutation({
    mutationFn: (actionId) => sdk.admin.exchanges.$id.inbound.shippingMethod.$actionId.delete({
      $id: id,
      $actionId: actionId
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddExchangeOutboundItems = (id, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.exchanges.$id.outbound.items.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateExchangeOutboundItems = (id, orderId, options) => {
  return useMutation({
    mutationFn: ({
      actionId,
      ...payload
    }) => {
      return sdk.admin.exchanges.$id.outbound.items.$actionId.mutate({
        $id: id,
        $actionId: actionId,
        ...payload
      });
    },
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRemoveExchangeOutboundItem = (id, orderId, options) => {
  return useMutation({
    mutationFn: (actionId) => sdk.admin.exchanges.$id.outbound.items.$actionId.delete({
      $id: id,
      $actionId: actionId
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddExchangeOutboundShipping = (id, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.exchanges.$id.outbound.shippingMethod.mutate({
      $id: id,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateExchangeOutboundShipping = (id, orderId, options) => {
  return useMutation({
    mutationFn: ({
      actionId,
      ...payload
    }) => sdk.admin.exchanges.$id.outbound.shippingMethod.$actionId.mutate({
      $id: id,
      $actionId: actionId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteExchangeOutboundShipping = (id, orderId, options) => {
  return useMutation({
    mutationFn: (actionId) => sdk.admin.exchanges.$id.outbound.shippingMethod.$actionId.delete({
      $id: id,
      $actionId: actionId
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useExchangeConfirmRequest = (id, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.exchanges.$id.request.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: returnsQueryKeys.all
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      queryClient.invalidateQueries({
        queryKey: exchangesQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCancelExchangeRequest = (id, orderId, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.exchanges.$id.request.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      queryClient.invalidateQueries({
        queryKey: exchangesQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: exchangesQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  useExchange,
  useExchanges,
  useCreateExchange,
  useCancelExchange,
  useAddExchangeInboundItems,
  useUpdateExchangeInboundItem,
  useRemoveExchangeInboundItem,
  useAddExchangeInboundShipping,
  useUpdateExchangeInboundShipping,
  useDeleteExchangeInboundShipping,
  useAddExchangeOutboundItems,
  useUpdateExchangeOutboundItems,
  useRemoveExchangeOutboundItem,
  useAddExchangeOutboundShipping,
  useUpdateExchangeOutboundShipping,
  useDeleteExchangeOutboundShipping,
  useExchangeConfirmRequest,
  useCancelExchangeRequest
};
