import { rankType } from '../../shared/protocols/rank/PtlOpen';
import { rankInfo } from '../../shared/protocols/type';
import { player } from '../../shared/protocols/user/type';
import { Rank } from './rank';


export class RankClslCross extends Rank {

    countMaxNum = 99999;
    minStar = Object.values(G.gc.clsl_dan)[Object.keys(G.gc.clsl_dan).length - 1].allStar;
    getType(): rankType {
        return 'clslCross';
    }
    // compare(other: rankInfo, cur: rankInfo): boolean {
    //     return cur.valArr[0] > other.valArr[0];
    // }
    // compareSort(a: rankInfo, b: rankInfo): number {
    //     return b.valArr[0] - a.valArr[0];
    // }
    
    // // 积分, 排名依据
    // getValArr(info: rankInfo):number|string {
    //     return info?.valArr[0] || 0
    // }

    // async getRankList(uid: string, {gud, min, max}) {
    //     let rankList = await this.getRankListRange(min, max);
    //     let rank = await this.getRankSortByOne(uid);
    //     let score = await this.getRankScore(uid)
    //     return {
    //         rankList: rankList,
    //         myRank: {
    //             rank: rank,
    //             player: gud,
    //             valArr: [score]
    //         }
    //     };
    // }
    
    async addNew(info: rankInfo) {
        this.queue.enqueue(async () => {
            // 积分大于配置的最小参数，更新数据
            if (info.valArr[0] >= this.minStar) {
                this.setRankData(info.player[this.findKey], info)
                this.db.updateOne({ type: this.type, idKey: info.player[this.findKey] }, { $set: { data: info } }, { upsert: true });
                // rankList.sort(this.compareSort);
            }
            // 积分小于配置，且用户数据存在时，删除
            else if (info.valArr[0] < this.minStar) {
                let rankInfo = await this.getRankData(info.player[this.findKey])
                if(rankInfo?.player) {
                    this.db.deleteOne({ type: this.type, idKey: info.player[this.findKey] });
                    this.delRankData(info.player[this.findKey])
                }
            }
        });
    }
}