import axios from 'axios';

const api = axios.create({
  baseURL: '/api',
});

export interface StockRank {
  code: string;
  name: string;
  pct_change: number;
  close: number;
}

export interface DashboardSummary {
  total_stocks: number;
  up_count: number;
  down_count: number;
  flat_count: number;
  total_turnover: number;
  avg_pct_change: number;
  limit_up_list: StockRank[];
  limit_down_list: StockRank[];
  high_100_list: StockRank[];
}

export interface DailySummary {
  date: string;
  total_stocks: number;
  up_count: number;
  down_count: number;
  flat_count: number;
  total_turnover: number;
  avg_pct_change: number;
  limit_up_10: number;
  limit_down_10: number;
  limit_up_20: number;
  limit_down_20: number;
  consecutive_limit_count: number;
}

export async function getDashboardSummary(): Promise<DashboardSummary> {
  const res = await api.get('/dashboard/summary');
  return res.data.data;
}

export async function getDailySummary(days = 30): Promise<DailySummary[]> {
  const res = await api.get('/dashboard/daily', { params: { days } });
  return res.data.data;
}

export interface ConsecutiveLimit {
  code: string;
  name: string;
  streak: number;
  close: number;
  pct_change: number;
}

export async function getConsecutiveLimits(): Promise<ConsecutiveLimit[]> {
  const res = await api.get('/dashboard/consecutive');
  return res.data.data;
}
