// 武将觉醒表
import { readFileAndParse, parseGoodStr } from '../util'
import { ABI_STAGE, FILENAME } from '../../consts';
import { RewardInter } from '../interface';
const _ = require('lodash');

export interface DicHeroWake {

    // 唯一id
    readonly id: number;
    // 职业类型
    readonly classType: number;
    // 品质
    readonly quality: number;
    // 彩星级
    readonly star: number;
    // 碎片数量
    readonly fragmentNum: number;
    // 消耗道具
    readonly consume: Array<RewardInter>;
    // 每阶升级属性
    readonly ceAttr: Map<number, number>

}

type KeysEnum<T> = { [P in keyof Required<T>]: true };
const DicHeroWakeKeys: KeysEnum<DicHeroWake> = {id: true, classType: true, quality: true, star: true, fragmentNum: true, consume: true, ceAttr: true};

export const dicHeroWake = new Map<string, DicHeroWake>();
export function loadHeroWake() {
    dicHeroWake.clear();
    
    let arr = readFileAndParse(FILENAME.DIC_HERO_WAKE);

    arr.forEach(o => {
        o.consume = parseGoodStr(o.consume);
        o.ceAttr = parseCeAttr(o);
        o.classType = o.class_type;
        dicHeroWake.set(`${o.classType}_${o.quality}_${o.star}`, _.pick(o, Object.keys(DicHeroWakeKeys)));
    });
    arr = undefined;
}

function parseCeAttr(elem) {
    let ceAttr = new Map<number, number>();
    ceAttr.set(ABI_STAGE.HP, elem.hp_up);
    ceAttr.set(ABI_STAGE.ATK, elem.atk_up);
    ceAttr.set(ABI_STAGE.DEF, elem.def_up);
    ceAttr.set(ABI_STAGE.MDEF, elem.mdef_up);
    return ceAttr;
}