import { useQuery } from '@tanstack/react-query';
import { getOHLCV } from '../api/ohlcv';
import { getScores } from '../api/scores';
import { getGateTargetLadder, getLevels } from '../api/sr-levels';
import { getSentiment } from '../api/sentiment';
import { getFundamentals } from '../api/fundamentals';
import * as tradesApi from '../api/trades';

export function useTickerDetail(symbol: string, includeGateTargetLadder = false) {
  const ohlcv = useQuery({
    queryKey: ['ohlcv', symbol],
    queryFn: () => getOHLCV(symbol),
    enabled: !!symbol,
  });

  const scores = useQuery({
    queryKey: ['scores', symbol],
    queryFn: () => getScores(symbol),
    enabled: !!symbol,
  });

  const srLevels = useQuery({
    queryKey: ['sr-levels', symbol],
    queryFn: () => getLevels(symbol),
    enabled: !!symbol,
  });

  const gateTargetLadder = useQuery({
    queryKey: ['gate-target-ladder', symbol],
    queryFn: () => getGateTargetLadder(symbol),
    enabled: !!symbol && includeGateTargetLadder,
  });

  const sentiment = useQuery({
    queryKey: ['sentiment', symbol],
    queryFn: () => getSentiment(symbol),
    enabled: !!symbol,
  });

  const fundamentals = useQuery({
    queryKey: ['fundamentals', symbol],
    queryFn: () => getFundamentals(symbol),
    enabled: !!symbol,
  });

  const trades = useQuery({
    queryKey: ['trades', symbol],
    queryFn: () => tradesApi.bySymbol(symbol),
    enabled: !!symbol,
  });

  return {
    ohlcv,
    scores,
    srLevels,
    gateTargetLadder,
    sentiment,
    fundamentals,
    trades,
  };
}
