import {
  returnsQueryKeys
} from "./chunk-OQTL7PXK.js";
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/claims.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var CLAIMS_QUERY_KEY = "claims";
var claimsQueryKeys = queryKeysFactory(CLAIMS_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: claimsQueryKeys.lists() });
};
var useClaim = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: async () => sdk.vendor.claims.$id.query({ $id: id, ...query }),
    queryKey: claimsQueryKeys.detail(id, query),
    ...options
  });
  return { ...data, ...rest };
};
var useClaims = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: async () => sdk.vendor.claims.query({ ...query }),
    queryKey: claimsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateClaim = (orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.claims.mutate(payload),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCancelClaimBegin = (claimId, orderId, options) => {
  return useMutation({
    mutationFn: () => sdk.vendor.claims.$id.request.delete({ $id: claimId }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRequestClaim = (claimId, orderId, options) => {
  return useMutation({
    mutationFn: () => sdk.vendor.claims.$id.request.mutate({ $id: claimId }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddClaimInboundItems = (claimId, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.claims.$id.inbound.items.mutate({
      $id: claimId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddClaimInboundShipping = (claimId, orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.claims.$id.inbound.shippingMethod.mutate({
      $id: claimId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateClaimInboundItem = (claimId, orderId, options) => {
  return useMutation({
    mutationFn: ({ actionId, $actionId: _ignored, ...payload }) => sdk.vendor.claims.$id.inbound.items.$actionId.mutate({
      $id: claimId,
      $actionId: actionId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRemoveClaimInboundItem = (claimId, orderId, options) => {
  return useMutation({
    mutationFn: (actionId) => sdk.vendor.claims.$id.inbound.items.$actionId.delete({
      $id: claimId,
      $actionId: actionId
    }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      queryClient.invalidateQueries({ queryKey: returnsQueryKeys.details() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateClaimInboundShipping = (claimId, orderId, options) => {
  return useMutation({
    mutationFn: ({ actionId, $actionId: _ignored, ...payload }) => sdk.vendor.claims.$id.inbound.shippingMethod.$actionId.mutate({
      $id: claimId,
      $actionId: actionId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteClaimInboundShipping = (claimId, orderId, options) => {
  return useMutation({
    mutationFn: (actionId) => sdk.vendor.claims.$id.inbound.shippingMethod.$actionId.delete({
      $id: claimId,
      $actionId: actionId
    }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useClaimConfirmRequest = useRequestClaim;
var useCancelClaimRequest = useCancelClaimBegin;

export {
  useClaim,
  useClaims,
  useCreateClaim,
  useCancelClaimBegin,
  useAddClaimInboundItems,
  useAddClaimInboundShipping,
  useUpdateClaimInboundItem,
  useRemoveClaimInboundItem,
  useUpdateClaimInboundShipping,
  useDeleteClaimInboundShipping,
  useClaimConfirmRequest,
  useCancelClaimRequest
};
