import { ApiCall } from "tsrpc";
import { WangZheRongYaofun } from "../../public/wzry";
import { ReqCatGroup, ResCatGroup } from "../../shared/protocols/wzry/PtlCatGroup";

export default async function (call: ApiCall<ReqCatGroup, ResCatGroup>) {
    // let status = await WangZheRongYaofun.getWangZheStatus()
    // if (status.status < 5) {
    //     // 未到报名时间
    //     return call.error('', { code: -1, message: globalThis.lng.wzry_5 })
    // }
    let _where = {};
    let _num = {
        "256": 4,
        "64": 32
    };
    if (call.req.deep == 256 || call.req.deep == 64) {    // 4个人
        _where['groupinfo.order'] = { $gt: (call.req.group - 1) * _num[call.req.deep], $lte: (call.req.group) * _num[call.req.deep] };
        if (call.req.deep == 64) _where["deep"] = { $gte: 3 };
    } else {
        _where["deep"] = { $gte: 6 };
    }


    let groupList = await WangZheRongYaofun.getFightGroup(call, _where);
    if (!groupList) {
        // 未到时间
        return call.error('', { code: -3/* , message: globalThis.lng.wzry_11 */ });
    }

    call.succ({ grouplist: groupList });
}