import {
  inventoryItemLevelsQueryKeys,
  inventoryItemsQueryKeys
} from "./chunk-5CK6XEFV.js";
import {
  queryClient
} from "./chunk-RHKRREUU.js";
import {
  queryKeysFactory
} from "./chunk-ZA2KFUFR.js";
import {
  sdk
} from "./chunk-ZBWL72TB.js";

// 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 useReservationItem = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryKey: reservationItemsQueryKeys.detail(id),
    queryFn: () => sdk.admin.reservations.$id.query({ $id: id, ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useReservationItems = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.reservations.query({ ...query }),
    queryKey: reservationItemsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useUpdateReservationItem = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.reservations.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: reservationItemsQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: reservationItemsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemLevelsQueryKeys.details()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCreateReservationItem = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.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
  });
};
var useDeleteReservationItem = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.reservations.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: reservationItemsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: reservationItemsQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemsQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: inventoryItemLevelsQueryKeys.details()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  reservationItemsQueryKeys,
  useReservationItem,
  useReservationItems,
  useUpdateReservationItem,
  useCreateReservationItem,
  useDeleteReservationItem
};
