import { useQuery } from '@tanstack/react-query';
import { api } from '@/shared/lib/apiClient';

/**
 * useCommandData — Command Pillar data
 * Fetches KPIs, AI priority cards, and pipeline stage summary.
 */
export function useCommandData() {
  return useQuery({
    queryKey: ['command-data'],
    queryFn:  () => api.get<CommandData>('/dashboard/morning-brief'),
    staleTime: 60_000,
    refetchInterval: 5 * 60_000,  // background refresh every 5min
  });
}

export interface CommandData {
  kpis: {
    label: string;
    value: string;
    delta?: string;
    deltaPositive?: boolean;
    sublabel?: string;
  }[];
  priorityCards: {
    id: string;
    type: 'qd_surge' | 'vault_engagement' | 'follow_up' | 'site_visit';
    headline: string;
    sublabel?: string;
    personId?: string;
    personName?: string;
    cta: string;
    urgency: 'high' | 'medium' | 'low';
  }[];
  pipelineStages: {
    id: string;
    label: string;
    count: number;
    value?: string;
  }[];
}
