import { useQuery, useMutation } from "@tanstack/react-query";
import * as api from "../service/Service";
import { OrdersResponse, OrderDetailResponse } from "../types/Types";

export const useGetOrders = (activeTab: string) => {
  return useQuery<OrdersResponse>({
    queryKey: ["orders", activeTab],
    queryFn: () => api.getOrders(activeTab),
    enabled: !!activeTab,
  });
};

export const useGetOrderDetail = (orderId: string) => {
  return useQuery<OrderDetailResponse>({
    queryKey: ["orderDetail", orderId],
    queryFn: () => api.getOrderDetail(orderId),
    enabled: !!orderId,
  });
};

export const useCancelOrder = () => {
  return useMutation({
    mutationFn: api.cancelOrder,
  });
};

export const useGetCancelReasons = () => {
  return useQuery({
    queryKey: ["cancelReasons"],
    queryFn: api.getCancelReasons,
  });
};

export const useGetReturnReasons = () => {
  return useQuery({
    queryKey: ["returnReasons"],
    queryFn: api.getReturnReasons,
  });
};

export const useReturnOrder = () => {
  return useMutation({
    mutationFn: api.returnOrder,
  });
};

export const useGetReturnOrder = () => {
  return useQuery({
    queryKey: ["returnOrder"],
    queryFn: api.getReturnOrder,
  });
};
