import {
  ordersQueryKeys
} from "./chunk-R74OHYTB.js";
import {
  reservationItemsQueryKeys
} from "./chunk-22XJUSMM.js";
import {
  inventoryItemsQueryKeys
} from "./chunk-BA2HXHTW.js";
import {
  queryClient
} from "./chunk-RHKRREUU.js";
import {
  sdk
} from "./chunk-RIN4CBRB.js";

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

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