import { xszmdb } from '../../api_s2c/event/xianshizhaomu/ApiOpen';
import { rankType } from '../../shared/protocols/rank/PtlOpen';
import { rankInfo } from '../../shared/protocols/type';
import { Rank } from './rank';


export class RankXszm extends Rank {
    getType(): rankType {
        return 'xszm';
    }
    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) + (b.player.vip || 0) * 100) - (a.valArr[0] * 10000 + (a.player.power || 0) + (a.player.vip || 0) * 100);
    }

    // 积分, 排名依据
    getValArr(info: rankInfo):number|string {
        if(!info.valArr) return 0
        let valArr = info.valArr[0]
        let power = info.player.power || 0
        let vip = info.player.vip || 0
        let res = valArr * 10000 + power + vip * 100
        return res
    }

    async getRankList(uid: string, { min, max }): Promise<{ rankList: rankInfo[]; myRank: rankInfo; }> {
        let data = await this.getRankData(uid);
        let rankList = await this.getRankListRange(min, max);
        let rank = await this.getRankSortByOne(uid);
        let score = await this.getRankScore(uid);
        return {
            rankList: rankList,
            myRank: {
                rank,
                player: data?.player || {},
                // roles: {}, // 剔除，待验证，前端如果未使用该参数，则可删除整个函数，继承Rank默认的getRankList
                valArr: [ score ]
            }
        };
    }
}