"use client";

import { useQuery } from "@tanstack/react-query";
import { useAuthSession } from "@/features/auth/stores/auth.store";
import { queryKeys } from "@/core/api";
import { getMeStatus } from "../api/meStatus.api";
import type { MeStatus } from "@customer-portal/domain/dashboard";

/**
 * Fetches aggregated customer status used by the dashboard (tasks, summary, gating signals).
 */
export function useMeStatus() {
  const { isAuthenticated } = useAuthSession();

  return useQuery<MeStatus, Error>({
    queryKey: queryKeys.me.status(),
    queryFn: () => getMeStatus(),
    enabled: isAuthenticated,
    refetchOnWindowFocus: false,
    refetchOnReconnect: false,
  });
}

export type UseMeStatusResult = ReturnType<typeof useMeStatus>;
