import { readFileAndParse } from '../util'
import { FILENAME, ACTIVITY_TYPE } from '../../consts'
type KeysEnum<T> = { [P in keyof Required<T>]: true };
const _ = require('lodash');

export interface DicActivityType {
    readonly id: number;
    // 活动类型
    readonly activityType: ACTIVITY_TYPE;
    // 类型变量名
    readonly name: string;
    // 类型描述
    readonly desc: string;
}

const DicActivityTypeKeys: KeysEnum<DicActivityType> = {
    id: true,
    activityType: true,
    name: true,
    desc: true,
};

export const dicActivityType = new Array<DicActivityType>();
export function loadActivityType() {
    dicActivityType.splice(0, dicActivityType.length);
    let arr = readFileAndParse(FILENAME.DIC_ACTIVITY_TYPE);
    arr.forEach(o => {
        o.desc = o.string;
        dicActivityType.push(_.pick(o, Object.keys(DicActivityTypeKeys)));
    });
    arr = undefined;
}