import { useQuery } from '@tanstack/react-query';
import { isAxiosError } from 'axios';
import { fetchProjectCommandCenter } from '@/features/projects/services/projectService';

export const commandCenterKey = (projectId: string) => ['projects', projectId, 'command-center'];

export function useProjectCommandCenter(projectId: string | undefined) {
  return useQuery({
    queryKey: commandCenterKey(projectId ?? ''),
    queryFn: () => fetchProjectCommandCenter(projectId!),
    enabled: Boolean(projectId),
    retry: (failureCount, error) =>
      !(isAxiosError(error) && error.response?.status === 404) && failureCount < 2,
  });
}
