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


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

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

    /************************月卡活动****************************/

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

        let playerData = await getPlayerMonthlyTicketData(activityId, serverId, roleId);
        if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
        return resResult(STATUS.SUCCESS, playerData);
    }

    /**
    * @description 领取月卡奖品
    * @param {BackendSession} session
    * @memberof MonthlyTicketHandler
    */
    async getMonthlyTicketReward(msg: { activityId: number }, session: BackendSession) {
        const { activityId } = msg;
        const roleId = session.get('roleId');
        const serverId = session.get('serverId');
        const sid = session.get('sid');
        const roleName = session.get('roleName');
        

        let result = await getPlayerMonthlyTicketDayReward(roleId, roleName, sid, serverId, activityId)
        if (result) {
            return resResult(STATUS.SUCCESS, Object.assign(result, {
                param: { activityId },
            }));
        }
        return resResult(STATUS.NO_MOTHLY_TICKET_REWARD);
    }
}
