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

export interface ProfileResponse {
  uuid: string;
  firstName: string;
  lastName: string;
  email: string;
  mobileNumber: string;
  dialCode: string;
  emailVerified: boolean;
  roles: string[];
  profilePicture?: string;
}

export default function useProfileFetch() {
  const { data, isFetching, isError, error } = useQuery({
    queryKey: ["profile"],
    queryFn: async () => {
      const res = await apiGet<ProfileResponse>(PROFILE_ENDPOINTS.PROFILE);
      return res.data;
    },
    staleTime: 5 * 60 * 1000,
  });

  return { profile: data, loading: isFetching, error, isError };
}
