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 {
    // 科技树唯一id
    readonly id: number;
    // 目标品质
    readonly quality: number;
    // 相同品质下细分等级
    readonly qualityLevel: number;
    // 前置点需求
    readonly prePositions: number[];
    // 图纸最多张数
    readonly max: number;
    // 需要的功勋
    readonly honourConsume: RewardInter[];
    // 研发需要的资金
    readonly fundConsume: number;
    // 研发需要的时间
    readonly timeConsume: number;
    // 建筑物id
    readonly structureLevel: number;
}

const DicArmyDevelopConsumeKeys: KeysEnum<DicArmyDevelopConsume> = {
    id: true,
    quality: true,
    qualityLevel: true,
    prePositions: true,
    max: true,
    honourConsume: true,
    fundConsume: true,
    timeConsume: true,
    structureLevel: 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;
}