import {
  inventoryItemLevelsQueryKeys,
  inventoryItemsQueryKeys
} from "./chunk-YAUGB4LD.js";
import {
  queryClient
} from "./chunk-RHKRREUU.js";
import {
  queryKeysFactory
} from "./chunk-ZA2KFUFR.js";
import {
  sdk
} from "./chunk-DTGEFKK4.js";

// src/hooks/api/orders.tsx
import {
  useMutation as useMutation2,
  useQuery as useQuery2
} from "@tanstack/react-query";

// src/hooks/api/reservations.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var RESERVATION_ITEMS_QUERY_KEY = "reservation_items";
var reservationItemsQueryKeys = queryKeysFactory(
  RESERVATION_ITEMS_QUERY_KEY
);
var useReservationItems = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.vendor.reservations.query({ ...query }),
    queryKey: reservationItemsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateReservationItem = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.reservations.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: reservationItemsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemLevelsQueryKeys.details()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

// src/hooks/api/orders.tsx
var ORDERS_QUERY_KEY = "orders";
var _orderKeys = queryKeysFactory(ORDERS_QUERY_KEY);
_orderKeys.preview = function(id) {
  return [this.detail(id), "preview"];
};
_orderKeys.changes = function(id) {
  return [this.detail(id), "changes"];
};
var ordersQueryKeys = _orderKeys;
var useOrder = (id, query, options) => {
  const { data, ...rest } = useQuery2({
    queryFn: async () => sdk.vendor.orders.$id.query({ $id: id, ...query }),
    queryKey: ordersQueryKeys.detail(id, query),
    ...options
  });
  return { ...data, ...rest };
};
var useOrderPreview = (id, query, options) => {
  const { data, ...rest } = useQuery2({
    queryFn: async () => sdk.vendor.orders.$id.preview.query({ $id: id, ...query }),
    queryKey: ordersQueryKeys.preview(id),
    ...options
  });
  return { ...data, ...rest };
};
var useOrders = (query, options) => {
  const { data, ...rest } = useQuery2({
    queryFn: async () => sdk.vendor.orders.query({ ...query }),
    queryKey: ordersQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useOrderChanges = (id, query, options) => {
  const { data, ...rest } = useQuery2({
    queryFn: async () => sdk.vendor.orders.$id.changes.query({ $id: id, ...query }),
    queryKey: ordersQueryKeys.changes(id),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateOrderFulfillment = (orderId, options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.vendor.orders.$id.fulfillments.mutate({ $id: orderId, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.all
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      queryClient.invalidateQueries({
        queryKey: reservationItemsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.details()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCancelOrderFulfillment = (orderId, fulfillmentId, options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.vendor.orders.$id.fulfillments.$fulfillmentId.cancel.mutate({
      $id: orderId,
      $fulfillmentId: fulfillmentId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.all
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      queryClient.invalidateQueries({
        queryKey: reservationItemsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.details()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCreateOrderShipment = (orderId, fulfillmentId, options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.vendor.orders.$id.fulfillments.$fulfillmentId.shipments.mutate({
      $id: orderId,
      $fulfillmentId: fulfillmentId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.all
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useMarkOrderFulfillmentAsDelivered = (orderId, fulfillmentId, options) => {
  return useMutation2({
    mutationFn: () => sdk.vendor.orders.$id.fulfillments.$fulfillmentId.markAsDelivered.mutate({
      $id: orderId,
      $fulfillmentId: fulfillmentId
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.all
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCancelOrder = (orderId, options) => {
  return useMutation2({
    mutationFn: () => sdk.vendor.orders.$id.cancel.mutate({ $id: orderId }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.detail(orderId)
      });
      queryClient.invalidateQueries({
        queryKey: ordersQueryKeys.preview(orderId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useOrderCommissionLines = (id, options) => {
  const { data, ...rest } = useQuery2({
    queryFn: async () => sdk.vendor.orders.$id.commissionLines.query({ $id: id }),
    queryKey: ordersQueryKeys.detail(`${id}/commission-lines`),
    ...options
  });
  return { commission_lines: data?.commission_lines ?? [], ...rest };
};

export {
  useReservationItems,
  useCreateReservationItem,
  ordersQueryKeys,
  useOrder,
  useOrderPreview,
  useOrders,
  useOrderChanges,
  useCreateOrderFulfillment,
  useCancelOrderFulfillment,
  useCreateOrderShipment,
  useMarkOrderFulfillmentAsDelivered,
  useCancelOrder,
  useOrderCommissionLines
};
