import { readFileAndParse, parseGoodStr } from '../util'
import { FILENAME } from '../../consts'
import { RewardInter } from '../interface';

export interface DicRankRewads {
    readonly id: number;
    readonly seasonNum: number;
    readonly min: number;
    readonly max: number;
    readonly reward:  Array<RewardInter>;

}


export const dicRankRewads = new Map<number, DicRankRewads[]>();
export const dicRankMax = new Map<number, DicRankRewads>();
export function loadPvpRankReward() {
    dicRankRewads.clear();
    dicRankMax.clear();
    
    let arr = readFileAndParse(FILENAME.DIC_PVP_RANK_REWARD);

    arr.forEach(o => {
        o.reward = parseGoodStr(o.reward);
        if(!dicRankRewads.has(o.seasonNum)) {
            dicRankRewads.set(o.seasonNum, []);
        }
        dicRankRewads.get(o.seasonNum).push(o);

        if (!dicRankMax.has(o.seasonNum) || o.min > dicRankMax.get(o.seasonNum).min) {
            dicRankMax.set(o.seasonNum, o);
        }
    });
    arr = undefined;
}