import { ApiCall } from "tsrpc";
import { ReqRank, ResRank } from "../../cross/protocols/kbzz/PtlRank";
import { RankKbzz } from '../../public/rank/rank_kbzz';


export default async function (call: ApiCall<ReqRank, ResRank>) {
    let page = call.req.page || 0
    let offset = call.req.offset || -1 // 预防未查询到的调用，按原逻辑查询全部，避免引起未知问题
    let _cunzai = await G.mongodb.collection('kbzzGroupTroop').findOne({})
    if (!_cunzai) {
        return call.error('', { code: -1, message: '功能未开放' })
    }
    let db = await G.mongodb.collection('kbzzGroupUser').findOne({ uid: call.req.uid });
    let group = db?.group || 0;
    let {min, max} = RankKbzz.pageToMin(page, offset)
    let rank = await RankKbzz.groupList[group].getRankList(call.req.uid, { min, max });

    call.succ({
        ...rank
    });
}