import { ApiCall } from "tsrpc";
import { FightFun } from "../../public/fight";
import { PlayerFun } from "../../public/player";
import { WangZheRongYaofun } from "../../public/wzry";
import { ReqBaoMing, ResBaoMing } from "../../shared/protocols/wzry/PtlBaoMing";
import { PublicShared } from "../../shared/public/public";
import { HongDianChange } from "../hongdian/fun";

export default async function (call: ApiCall<ReqBaoMing, ResBaoMing>) {
    let _con = await WangZheRongYaofun.getCon();
    if (call.conn.gud.lv < G.gc.openCond.wzrybm.and.lv) {
        // 等级不足
        return call.error('', { code: -1/* , message: globalThis.lng.wzry_1  */ });
    }

    let status = await WangZheRongYaofun.getWangZheStatus();
    if (status.status != 1) {
        // 未到报名时间
        return call.error('', { code: -2/* , message: globalThis.lng.wzry_2  */ });
    }

    // 个人数据
    let _mydata = await WangZheRongYaofun.getMyData(call);
    if (_mydata.isbm) {
        // 重复报名
        return call.error('', { code: -3/* , message: globalThis.lng.wzry_3 */ });
    }

    // 周key
    let zkey = await PublicShared.getToWeek();
    // 报名
    await WangZheRongYaofun.setWzryBaoMing(call, { zkey: zkey, isbm: 1 });

    // 发奖
    let _prize: atn[] = _con.wangzhe.bmprize;
    await PlayerFun.sendPrize(call, _prize);

    HongDianChange.sendChangeKey(call.uid, ['wzryhd']);

    call.succ({ prize: _prize });
}