import { ApiCall } from "tsrpc";
import { ActionLog } from '../../../public/actionLog/actionLog';
import { HuoDongFun } from "../../../public/huodongfun";
import { call } from "../../../public/player";
import { ReqOpen, ResOpen } from "../../../shared/protocols/event/qiridenglu/PtlOpen";

export default async function (call: ApiCall<ReqOpen, ResOpen>) {
    let _hdinfo = await HuoDongFun.getHdidInfo(call, call.req.hdid)
    if (!_hdinfo || Object.keys(_hdinfo).length <= 0) {
        // 无此活动
        return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 })
    }

    let _dbType: `qiridenglu${number}` = `qiridenglu${call.req.hdid}`

    let db = await G.mongodb.cEvent(_dbType).findOne({ uid: call.uid, type: _dbType });
    let day = await ActionLog.getRetainLog(call.uid, `login_day_qiridenglu_${call.req.hdid}`);

    call.succ({
        loginDay: day,
        recPrize: db?.recPrize || [],
        hdinfo: _hdinfo
    });
}


// 符合时间的七日登录活动记录天数
export async function qiRiDengLuAddDay(call: call) {
    // @ts-ignore
    let _sDayhdList = await HuoDongFun.gethdList(call, 6)
    _sDayhdList && _sDayhdList.forEach(element => {
        ActionLog.addRetainLog(call.uid, { key: `login_day_qiridenglu_${element.hdid}`, val: 1 });
    });
}

