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 DicArmyTrainJuDian {

    readonly id: number;
    // 目标品质
    readonly trainInstances: Array<{hid: number, warId: number, progress: number}>;
    readonly heroRewards: Array<{id: number, count: number}>;
      // 进阶奖励
    readonly jinjieReward: RewardInter[];
    readonly soloRewardRatio: number;
}

const DicArmyTrainJuDianKeys: KeysEnum<DicArmyTrainJuDian> = {
    id: true,
    trainInstances: true,
    heroRewards: true,
    jinjieReward: true,
    soloRewardRatio: true
};

export const dicArmyTrainJuDian = new Map<number, DicArmyTrainJuDian>();
export function loadArmyTrainJuDian() {

    let arr = readFileAndParse(FILENAME.DIC_ARMY_TRAIN_JU_DIAN);

    arr.forEach(o => {
        o.trainInstances = o.gkid.split('|').map(element => {
            let arr = element.split('&');
            return {hid: parseInt(arr[0]), warId: parseInt(arr[1]), progress: parseInt(arr[2])};
        });
        o.jinjieReward = parseGoodStr(o.jinjieReward);
    
        o.heroRewards = parseGoodStr(o.shilianReward);
    
        dicArmyTrainJuDian.set(o.id,_.pick(o, Object.keys(DicArmyTrainJuDianKeys)));
    });
    arr = undefined;
}