import { useMutation, useQuery } from "@tanstack/react-query";
import * as api from "../service/OrderService";

export const useGetNativeOrders = (
  page: number = 1,
  status: string = "all"
) => {
  const { data, isLoading, error } = useQuery({
    queryKey: ["orders", page, status],
    queryFn: () => api.getNativeOrders(page, status),
  });
  return { data, isLoading, error };
};

export const useGetSellerOrders = (
  page: number = 1,
  status: string = "all"
) => {
  const { data, isLoading, error } = useQuery({
    queryKey: ["orders", page, status],
    queryFn: () => api.getSellerOrders(page, status),
  });
  return { data, isLoading, error };
};

export const useGetOrderDetailUser = (id: string) => {
  return useQuery({
    queryKey: ["order-detail-user", id],
    queryFn: () => api.getOrderDetailUser(id),
    enabled: !!id,
  });
};

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

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

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

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

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

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