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

export interface DicTrainSoloReward {

    readonly id: number;
    // 目标品质
    readonly winScore: number;
    readonly failScore: number;
    readonly winHonour: number;
    readonly failHonour: number;

}

const DicTrainSoloRewardKeys: KeysEnum<DicTrainSoloReward> = {
    id: true,
    winScore: true,
    failScore: true,
    winHonour: true,
    failHonour: true,
};

export const dicTrainSoloReward = new Map<number, DicTrainSoloReward>();
export function loadTrainSoloReward() {
    dicTrainSoloReward.clear();
    
    let arr = readFileAndParse(FILENAME.DIC_ARMY_TRAIN_SOLO_REWARD);

    arr.forEach(o => {
        o.winReward.split('|').map(cur=>{
            let arr = cur.split('&');
            if (arr[0] == 1) {
                o.winScore = parseInt(arr[1]);
            } else if (arr[0] == 2) {
                o.winHonour = parseInt(arr[1]);
            }
        })
        o.failReward.split('|').map(cur=>{
            let arr = cur.split('&');
            if (arr[0] == 1) {
                o.failScore = parseInt(arr[1]);
            } else if (arr[0] == 2) {
                o.failHonour = parseInt(arr[1]);
            }
        })
        dicTrainSoloReward.set(o.id,_.pick(o, Object.keys(DicTrainSoloRewardKeys)));
    });
    arr = undefined;
}