import { ApiCall } from "tsrpc";
import { TanXianFun } from '../../public/tanxian';
import { ReqOpen, ResOpen } from "../../shared/protocols/tanxian/PtlOpen";
import { PublicShared } from '../../shared/public/public';
import {TeQuanFun} from "../../public/tequan";

export default async function (call: ApiCall<ReqOpen, ResOpen>) {
    let data = await TanXianFun.getData(call, call.req.cache);
    let { receiveLastId } = TanXianFun.getLastMapId(data.receivePrizeConfId)// 获取当前的领取进度

    if (PublicShared.getToDayZeroTime() > data.resetTime) {
        data.useFastGuaJiNum = 0;
        data.useFreeGuaJiNum = 0;
        TanXianFun.changeData(call, { useFastGuaJiNum: 0, useFreeGuaJiNum:0, resetTime: G.time });
    }

    call.succ({
        zztqfreeNum: await TeQuanFun.getTxFreeNum(call),
        ...data,
        fastGuaJiNum: await TanXianFun.getFastGuaJiNum(call),
        receiveLastId
    });
}