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

type PlatformSettingsResponse = {
  logo: string;
  appName: string;
  email: string;
  phone: string;
  dialCode: string;
  currency: string;
};

export default function useFetchPlatformSettings() {
  const { data, isPending, error } = useQuery({
    queryKey: ["platform-settings"],
    queryFn: async () => {
      const response = await apiGet<PlatformSettingsResponse>(
        SETTINGS_ENDPOINTS.PLATFORM,
      );
      return response.data;
    },
    staleTime: 10 * 60 * 1000,
  });

  return {
    platformSettings: data,
    loading: isPending,
    error,
  };
}
