import { useQuery } from "@tanstack/react-query";
import { apiGet } from "../../../../lib/api/methods";
import { ADMIN_CONTACTS } from "./endpoints";

export type AdminContactRequestDetail = {
  uuid: string;
  firstName: string;
  lastName: string;
  email: string;
  dialCode: string;
  phoneNumber: string;
  query: string;
  createdAt: string;
};

export default function useContactRequestDetail(uuid?: string) {
  const { data, isPending, isError, error } = useQuery({
    queryKey: ["contact-request-detail", uuid],
    queryFn: async () => {
      if (!uuid) throw new Error("Contact UUID is required");
      const res = await apiGet<AdminContactRequestDetail>(
        ADMIN_CONTACTS.GET_CONTACT_REQUEST_DETAIL(uuid),
      );
      return res.data;
    },
    staleTime: 5 * 60 * 1000,
    retry: false,
    enabled: !!uuid,
  });

  return {
    contact: data,
    loading: isPending,
    error,
    isError,
  };
}
