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

// src/hooks/api/returns.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var RETURNS_QUERY_KEY = "returns";
var returnsQueryKeys = queryKeysFactory(RETURNS_QUERY_KEY);
var useReturn = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: async () => sdk.admin.returns.$id.query({ $id: id, ...query }),
    queryKey: returnsQueryKeys.detail(id, query),
    ...options
  });
  return { ...data, ...rest };
};
var useReturns = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: async () => sdk.admin.returns.query({ ...query }),
    queryKey: returnsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useInitiateReturn = (orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.returns.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCancelReturn = (id, orderId, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.returns.$id.cancel.mutate({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId),
        refetchType: "all"
        // We want preview to be updated in the cache immediately
      });
      queryClient.invalidateQueries({
        queryKey: returnsQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: returnsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useConfirmReturnRequest = (id, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.returns.$id.request.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      queryClient.invalidateQueries({
        queryKey: returnsQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: returnsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCancelReturnRequest = (id, orderId, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.returns.$id.request.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId),
        refetchType: "all"
        // We want preview to be updated in the cache immediately
      });
      queryClient.invalidateQueries({
        queryKey: returnsQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: returnsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddReturnItem = (id, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.returns.$id.requestItems.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateReturnItem = (id, orderId, options) => {
  return useMutation({
    mutationFn: ({
      actionId,
      ...payload
    }) => {
      return sdk.admin.returns.$id.requestItems.$actionId.mutate({
        $id: id,
        $actionId: actionId,
        ...payload
      });
    },
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRemoveReturnItem = (id, orderId, options) => {
  return useMutation({
    mutationFn: (actionId) => sdk.admin.returns.$id.requestItems.$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 useUpdateReturn = (id, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => {
      return sdk.admin.returns.$id.mutate({ $id: id, ...payload });
    },
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddReturnShipping = (id, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.returns.$id.shippingMethod.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateReturnShipping = (id, orderId, options) => {
  return useMutation({
    mutationFn: ({
      actionId,
      ...payload
    }) => sdk.admin.returns.$id.shippingMethod.$actionId.mutate({
      $id: id,
      $actionId: actionId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteReturnShipping = (id, orderId, options) => {
  return useMutation({
    mutationFn: (actionId) => sdk.admin.returns.$id.shippingMethod.$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 useInitiateReceiveReturn = (id, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.returns.$id.receive.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddReceiveItems = (id, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.returns.$id.receiveItems.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateReceiveItem = (id, orderId, options) => {
  return useMutation({
    mutationFn: ({
      actionId,
      ...payload
    }) => {
      return sdk.admin.returns.$id.receiveItems.$actionId.mutate({
        $id: id,
        $actionId: actionId,
        ...payload
      });
    },
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRemoveReceiveItems = (id, orderId, options) => {
  return useMutation({
    mutationFn: (actionId) => {
      return sdk.admin.returns.$id.receiveItems.$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 useAddDismissItems = (id, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.returns.$id.dismissItems.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateDismissItem = (id, orderId, options) => {
  return useMutation({
    mutationFn: ({
      actionId,
      ...payload
    }) => {
      return sdk.admin.returns.$id.dismissItems.$actionId.mutate({
        $id: id,
        $actionId: actionId,
        ...payload
      });
    },
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRemoveDismissItem = (id, orderId, options) => {
  return useMutation({
    mutationFn: (actionId) => {
      return sdk.admin.returns.$id.dismissItems.$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 useConfirmReturnReceive = (id, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.returns.$id.receive.confirm.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      queryClient.invalidateQueries({
        queryKey: returnsQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: returnsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCancelReceiveReturn = (id, orderId, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.returns.$id.receive.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId),
        refetchType: "all"
        // We want preview to be updated in the cache immediately
      });
      queryClient.invalidateQueries({
        queryKey: returnsQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: returnsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  returnsQueryKeys,
  useReturn,
  useReturns,
  useInitiateReturn,
  useCancelReturn,
  useConfirmReturnRequest,
  useCancelReturnRequest,
  useAddReturnItem,
  useUpdateReturnItem,
  useRemoveReturnItem,
  useUpdateReturn,
  useAddReturnShipping,
  useUpdateReturnShipping,
  useDeleteReturnShipping,
  useInitiateReceiveReturn,
  useAddReceiveItems,
  useUpdateReceiveItem,
  useRemoveReceiveItems,
  useAddDismissItems,
  useUpdateDismissItem,
  useRemoveDismissItem,
  useConfirmReturnReceive,
  useCancelReceiveReturn
};
