import { useReducer } from 'react'
import {
    getStatistics, getArticleSummary, getFanGrowth, getFansAttribute, getFansActive, getFansInteractive, getFansKeep, Fans, getStatisticsMpId
} from '@/services/operating/operate'
import { useAjax } from '@/Hook/useAjax'
type State = {
    fansData?: any,//对应公众号头部粉丝数据
}
export type Action = {
    type: 'setFansData',
    params?: any
}
export function reducer(state: State, action: Action) {
    let { type, params } = action
    switch (type) {
        case 'setFansData':
            return { ...state, fansData: params.fansData }
        default:
            return state;
    }
}

export default function useWxGroupList() {
    const [state, dispatch] = useReducer(reducer,{})
    /**总览统计 */
    const statistics = useAjax((params: {userId: number}) => getStatistics(params))
    /**指定公众号的统计数据 */
    const statisticsMpId = useAjax((mpId) => getStatisticsMpId(mpId))
    /**图文分析 */
    const articleSummary = useAjax((params: Fans) => getArticleSummary(params))
    /**粉丝增长 */
    const fanGrowth = useAjax((params: Fans) => getFanGrowth(params))
    /**粉丝属性 */
    const fansAttribute = useAjax((params: Fans) => getFansAttribute(params))
    /**统计指定公众号粉丝的活跃数据 */
    const fansActive = useAjax((params: {
        mpId: string;
        timeDto: any;
    }) => getFansActive(params))
    /**统计指定公众号粉丝的互动数据 */
    const fansInteractive = useAjax((params: {
        mpId: string;
        timeDto: any;
    }) => getFansInteractive(params))
    /**统计指定公众号粉丝的忠诚度 */
    const fansKeep = useAjax((params: {
        mpId: string;
        statisticsKeepDto: any;
    }) => getFansKeep(params))


    return {
        state,
        dispatch,
        statistics,
        statisticsMpId,
        articleSummary,
        fanGrowth,
        fansAttribute,
        fansActive,
        fansInteractive,
        fansKeep
    }
}
