import { rankInfo } from '../../shared/protocols/type';
import { Rank } from './rank';


export class RankKbzz extends Rank {
    static groupList: RankKbzz[];
    static async init(reset = false) {
        if (reset) {
            G.mongodb.collection('rank').deleteMany({ type: { $regex: /^kbzz/ } });
        }

        this.groupList = [];
        let ds = await G.mongodb.collection('kbzzGroupTroop').find({}).toArray();
        let len = [...new Set(ds.map(d => d.group))].length;
        for (let g = 0; g < len; g++) {
            this.groupList.push(new this(g));
        }
    }
    constructor(public group: number) {
        super();
    }
    getType() {
        return ('kbzz' + this.group) as any;
    }
    compare(other: rankInfo, cur: rankInfo): boolean {
        return cur.valArr[0] > other.valArr[0];
    }
    compareSort(a: rankInfo, b: rankInfo): number {
        return (b.valArr[0] * 10000 + (b.player.power || 0) * 100 + (b.player.vip || 0)) - (a.valArr[0] * 10000 + (a.player.power || 0) * 100 + (a.player.vip || 0));
    }

    // 积分, 排名依据
    getValArr(info: rankInfo):number|string {
        if(!info?.valArr[0]) return 0
        let valArr = info.valArr[0] || 0
        return valArr
    }

    // async getRankList(uid: string, {min, max}) {
    //     let rankList = await this.getRankListRange(min, max);
    //     let gud = await this.getRankData(uid)
    //     return {
    //         rankList: rankList,
    //         myRank: {
    //             rank: await this.getRankSortByOne(uid),
    //             player: gud?.player || {},
    //             valArr: [(await G.mongodb.collection('kbzzGroupUser').findOne({ uid: uid }))?.score || 1000]
    //         }
    //     };
    // }

}