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

// src/hooks/api/order-edits.tsx
import { useMutation } from "@tanstack/react-query";
var invalidateOrder = (orderId) => {
  queryClient.invalidateQueries({ queryKey: ordersQueryKeys.details() });
  queryClient.invalidateQueries({ queryKey: ordersQueryKeys.preview(orderId) });
  queryClient.invalidateQueries({ queryKey: ordersQueryKeys.changes(orderId) });
};
var useCreateOrderEdit = (orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.orderEdits.mutate(payload),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCancelOrderEdit = (orderId, options) => {
  return useMutation({
    mutationFn: () => sdk.vendor.orderEdits.$id.delete({ $id: orderId }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRequestOrderEdit = (orderId, options) => {
  return useMutation({
    mutationFn: () => sdk.vendor.orderEdits.$id.request.mutate({ $id: orderId }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useConfirmOrderEdit = (orderId, options) => {
  return useMutation({
    mutationFn: () => sdk.vendor.orderEdits.$id.confirm.mutate({ $id: orderId }),
    onSuccess: (data, variables, context) => {
      invalidateOrder(orderId);
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddOrderEditItems = (orderId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.orderEdits.$id.items.mutate({ $id: orderId, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateOrderEditAddedItem = (orderId, options) => {
  return useMutation({
    mutationFn: ({ $actionId, ...payload }) => sdk.vendor.orderEdits.$id.items.$actionId.mutate({
      $id: orderId,
      $actionId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRemoveOrderEditAddedItem = (orderId, options) => {
  return useMutation({
    mutationFn: (actionId) => sdk.vendor.orderEdits.$id.items.$actionId.delete({
      $id: orderId,
      $actionId: actionId
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateOrderEditOriginalItem = (orderId, options) => {
  return useMutation({
    mutationFn: ({ $itemId, ...payload }) => sdk.vendor.orderEdits.$id.items.item.$itemId.mutate({
      $id: orderId,
      $itemId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  useCreateOrderEdit,
  useCancelOrderEdit,
  useRequestOrderEdit,
  useConfirmOrderEdit,
  useAddOrderEditItems,
  useUpdateOrderEditAddedItem,
  useRemoveOrderEditAddedItem,
  useUpdateOrderEditOriginalItem
};
