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

    readonly id: number;
    // 目标品质
    readonly quality: number;
    readonly starLevel: number;
    readonly prePositions: Array<number>;
    readonly honourConsume: Array<RewardInter>;
    readonly fundConsume: number;
    readonly timeConsume: number;
}

const DicArmyDevelopConsumeKeys: KeysEnum<DicArmyDevelopConsume> = {
    id: true,
    quality: true,
    starLevel: true,
    prePositions: true,
    honourConsume: true,
    fundConsume: true,
    timeConsume: true
};

export const dicArmyDevelopConsume = new Map<number, DicArmyDevelopConsume>();
export function loadArmyDevelopConsume() {
    dicArmyDevelopConsume.clear();
    let arr = readFileAndParse(FILENAME.DIC_ARMY_DEVELOPMENTCONSUME);

    arr.forEach(o => {
        o.honourConsume = parseGoodStr(o.honourConsume);
        o.prePositions = [];
        o.preposition.split('&').map(element => {
            if (!!parseInt(element))  
                o.prePositions.push(parseInt(element));
        });
    
        dicArmyDevelopConsume.set(o.id,_.pick(o, Object.keys(DicArmyDevelopConsumeKeys)));
    });
    arr = undefined;
}