import request from './request';

export interface WorksStats {
  totalCount: number;
  totalPlayCount: number;
  totalLikeCount: number;
  totalCommentCount: number;
  totalShareCount: number;
}

export interface CommentsStats {
  totalCount: number;
  unreadCount: number;
  todayCount: number;
}

// 单个平台的趋势数据
export interface PlatformTrendItem {
  platform: string;       // 平台标识
  platformName: string;   // 平台中文名
  fansIncrease: number[]; // 涨粉数
  views: number[];        // 播放数
  likes: number[];        // 点赞数
  comments: number[];     // 评论数
}

// 趋势数据（按平台分组）
export interface TrendData {
  dates: string[];                  // 日期数组
  platforms: PlatformTrendItem[];   // 各平台数据
}

export interface TrendParams {
  days?: number;
  accountId?: number;
}

export const dashboardApi = {
  // 获取作品统计
  getWorksStats(): Promise<WorksStats> {
    return request.get('/api/works/stats');
  },

  // 获取评论统计
  getCommentsStats(): Promise<CommentsStats> {
    return request.get('/api/comments/stats');
  },

  // 获取数据趋势（通过 Node 转发调用 Python API）
  async getTrend(params: TrendParams): Promise<TrendData> {
    const queryParams: Record<string, string> = {
      days: (params.days || 30).toString(),
    };
    if (params.accountId) {
      queryParams.account_id = params.accountId.toString();
    }
    
    const result = await request.get('/api/dashboard/trend', { params: queryParams });
    return result as TrendData;
  },
};
