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 DicArmyDonate {
    readonly id: number;
    readonly level: number;
    readonly fund: number;
    readonly boxRewards: Array<RewardInter>;
}

const DicArmyDonateKeys: KeysEnum<DicArmyDonate> = {
    id: true,
    level: true,
    fund: true,
    boxRewards: true
};

export const dicArmyDonate = new Map<number, DicArmyDonate>();
export function loadArmyDonate() {
    dicArmyDonate.clear();
    let arr = readFileAndParse(FILENAME.DIC_ARMY_DONATE_BOX_REWARD);
    
    arr.forEach(o => {
        o.boxRewards = parseGoodStr(o.boxReward);
        dicArmyDonate.set(o.id, _.pick(o, Object.keys(DicArmyDonateKeys)));
    });
    arr = undefined;
}