// 物品表
import { readFileAndParse, parseGoodStr, } from '../util'
import { FILENAME, } from '../../consts'
import { RewardInter } from '../interface';
const _ = require('lodash');

export interface DicTowerGift {
    // 奖励id
    readonly id: number;
    // 镇念塔层数
    readonly towerLv: number;
    // 奖励
    readonly reward: RewardInter[];
}

type KeysEnum<T> = { [P in keyof Required<T>]: true };
const DicTowerGiftKeys: KeysEnum<DicTowerGift> = {
    id: true,
    towerLv: true,
    reward: true,
}
export const dicTowerGift = new Map<number, DicTowerGift>();

export function loadTowerGift() {
    dicTowerGift.clear();    
    let arr = readFileAndParse(FILENAME.DIC_TOWER_GIFT);

    arr.forEach(o => {
        o.reward = parseGoodStr(o.reward);
        dicTowerGift.set(o.id, _.pick(o, Object.keys(DicTowerGiftKeys)));
    });

    arr = undefined;
}