import { readFileAndParse, parseGoodStr } from '../util'
import { FILENAME } from '../../consts'
type KeysEnum<T> = { [P in keyof Required<T>]: true };
import { RewardInter } from '../interface';
const _ = require('lodash');

export interface DicArmyBossRank {
    readonly id: number;
    readonly rankMin: number;
    readonly rankMax: number;
    readonly reward: Array<RewardInter>;
}

const DicArmyBossRankKeys: KeysEnum<DicArmyBossRank> = {
    id: true,
    rankMin: true,
    rankMax: true,
    reward: true,
};

export const dicArmyBossRank = new Array<DicArmyBossRank>();
export function loadArmyBossRank() {
    dicArmyBossRank.splice(0, dicArmyBossRank.length);
    let arr = readFileAndParse(FILENAME.DIC_ARMY_BOSS_RANK_REWARD);
    arr.forEach(o => {
        o.reward = parseGoodStr(o.reward);
        dicArmyBossRank.push(_.pick(o, Object.keys(DicArmyBossRankKeys)));
    });
    arr = undefined;
}