import { get } from '../http'

// API 参数类型定义
interface StatisticsParams {
  endDate?: string
  startDate?: string
}

interface ChartDataParams {
  endDate?: string
  startDate?: string
  type?: string
}

interface TagParams {
  keyword?: string
  page?: number
  size?: number
}

interface FeedbackParams {
  endDate?: string
  page?: number
  size?: number
  startDate?: string
  status?: string
  type?: string
}

interface UserVolumeParams {
  endDate?: string
  startDate?: string
  type?: 'day' | 'month' | 'year'
}

interface ConsumeVolumeParams {
  endDate?: string
  startDate?: string
  type?: 'day' | 'month' | 'year'
}

interface TimeRangeParams {
  endTime?: string
  startTime?: string
}

interface UserCount {
  compareYesterday: number
  count: number
}

interface NewCreateUserCount {
  compareYesterday: number
  count: number
}

interface AvgUserOnlineTime {
  compareYesterday: number
  count: number
}

interface AvgLifeCycle {
  compareYesterday: number
  count: number
}

interface WordBreakThroughCount {
  compareYesterday: number
  count: number
}

interface WordTestCount {
  compareYesterday: number
  count: number
}

interface DictUseCount {
  compareYesterday: number
  count: number
}

interface StrangeWordTableUseCount {
  compareYesterday: number
  count: number
}

export interface ActiveUserChartStatistic {
  count: number
  countDate: string
}

interface DailyWastageRateStatistic {
  count: number
  countDate: string
}

interface StatisticsData {
  activeUserChartStatistics: ActiveUserChartStatistic[]
  avgLifeCycle: AvgLifeCycle
  avgUserOnlineTime: AvgUserOnlineTime
  dailyWastageRateStatistics: DailyWastageRateStatistic[]
  dictUseCount: DictUseCount
  leCurrencyConsumeStatistics: any[] // 空数组，元素类型为 any
  maximumSimultaneousOnlineStatistics: any[] // 空数组，元素类型为 any
  newCreateUserCount: NewCreateUserCount
  sevenDayRetentionRateStatistics: any // null 用 any 表示
  strangeWordTableUseCount: StrangeWordTableUseCount
  userCount: UserCount
  wordBreakThroughCount: WordBreakThroughCount
  wordTestCount: WordTestCount
}

/**
 * @description: 获取首页数据
 * @param {object} data
 * @return {*}
 */
const getStatistics = async (params?: StatisticsParams) => {
  return await get<StatisticsData>('/homePage/getStatistics', params)
}
/**
 * @description: 获取刷题图表数据
 * @param {ChartDataParams} params
 * @return {*}
 */
const getQuestionAndComment = async (params?: ChartDataParams) => {
  return await get<any>('/homePage/getQuestionAndComment', params)
}
/**
 * @description: 获取刷试卷图表数据
 * @param {ChartDataParams} params
 * @return {*}
 */
const getPaperAndComment = async (params?: ChartDataParams) => {
  return await get<any>('/homePage/getPaperAndComment', params)
}
/**
 * @description: 获取热门标签图表数据
 * @param {TagParams} params
 * @return {*}
 */
const getHotTag = async (params?: TagParams) => {
  return await get<any>('/tag/hotTagList', params)
}

/**
 * @description: 获取反馈数据
 * @param {FeedbackParams} params
 * @return {*}
 */
const getSysFeedback = async (params?: FeedbackParams) => {
  return await get<any>('/sysFeedback/list', params)
}

/**
 * @description: 获取举报数据
 * @param {FeedbackParams} params
 * @return {*}
 */
const getFeedback = async (params?: FeedbackParams) => {
  return await get<any>('/feedback/list', params)
}
/**
 * @description: 获取用户量
 * @param {UserVolumeParams} params
 */
const getUserVolume = async (params?: UserVolumeParams) => {
  return await get<any>('/sysUser/getEveryDayUserCount', params)
}
/**
 * @description: 获取消耗量
 * @param {ConsumeVolumeParams} params
 */
const getConsumeVolume = async (params?: ConsumeVolumeParams) => {
  return await get<any>('/sysUser/getEveryDayConsume', params)
}
/**
 * @description: 查询工作台报表统计
 * @param {StatisticsParams} params
 */
const getWorkStationReport = async (params?: StatisticsParams) => {
  return await get<StatisticsData>('/sysUser/workStationReport', params)
}

/**
 * @description: 根据时间范围查询新增用户数量
 * @param {TimeRangeParams} params
 */
const getUserNumberByTime = async (params?: TimeRangeParams) => {
  return await get<any>('/sysUser/queryNewAccountByTimeRange', params)
}

const homeApi = {
  getStatistics,
  getQuestionAndComment,
  getPaperAndComment,
  getHotTag,
  getSysFeedback,
  getFeedback,
  getUserVolume,
  getConsumeVolume,
  getWorkStationReport,
  getUserNumberByTime,
}

export default homeApi
