import { Application, BackendSession, HandlerService, } from 'pinus';
import { resResult } from '../../../pubUtils/util';
import { STATUS } from '../../../consts';
import { getPlayerNewHeroGKData } from '../../../services/activity/newHeroGKService';


export default function (app: Application) {
    new HandlerService(app, {});
    return new NewHeroGKHandler(app);
}

export class NewHeroGKHandler {
    constructor(private app: Application) {
    }

    /************************新将演绎 (通用每日关卡,分页，自定义每个关卡开放的时间长短);(配置N个武将，每个武将有X个关卡；活动期间，*天(时间自定义)开启每个武将对应的一个关卡，只有第一次通关会获得奖励)****************************/

    /**
    * @description 获取关卡活动数据
    * @param {{ activityId: number}} msg
    * @param {BackendSession} session
    * @memberof NewHeroGKHandler
    */
    async getNewHeroGKActivity(msg: { activityId: number }, session: BackendSession) {
        const { activityId } = msg;
        const roleId = session.get('roleId');
        const serverId = session.get('serverId');

        let playerData = await getPlayerNewHeroGKData(activityId, serverId, roleId)

        if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);

        return resResult(STATUS.SUCCESS, playerData);
    }

    /**
        * @description 获取今日挑战的单个奖励
        * @param {{ activityId: number, pageIndex: number, index:number}} msg
        * @param {BackendSession} session
        * @memberof NewHeroGKHandler
        */
    async getGK(msg: { activityId: number, pageIndex: number, index: number }, session: BackendSession) {
        const { activityId, pageIndex, index } = msg;
        const roleId = session.get('roleId');
        const serverId = session.get('serverId');
        const sid = session.get('sid');
        const roleName = session.get('roleName');
        

        // let playerData = await getPlayerNewHeroGKData(activityId, serverId, roleId)
        // if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);

        // let dailyItemData: NewHeroGKItem = playerData.findNewHeroGKItem(pageIndex, index);
        // if (!dailyItemData) {
        //     return resResult(STATUS.ACTIVITY_DATA_ERROR);
        // }

        // if (dailyItemData.begin > playerData.todayIndex || dailyItemData.end < playerData.todayIndex) {
        //     return resResult(STATUS.ACTIVITY_DAY_INDEX_OVER);
        // }
        // // await challengeNewHeroGK(serverId, roleId, activityId, pageIndex, dailyItemData.gk)

        return resResult(STATUS.SUCCESS);
    }

}
