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

export interface DicTaskType {
    readonly id: TASK_TYPE;
    // 分类
    readonly name: string;
    // 描述
    readonly info: string;
    // taskParam怎么填
    readonly param: string;
    // condition怎么填
    readonly condition: string;
    // 累积类型 1-累积型 2-去做型
    readonly sumType: number; 
}

const DicTaskTypeKeys: KeysEnum<DicTaskType> = {
    id: true,
    name: true,
    info: true,
    param: true,
    condition: true,
    sumType: true,
};

export const dicTaskTypeDesc = new Array<DicTaskType>();
export const taskDescByType = new Map<number, DicTaskType>();
export function loadTaskType() {
    dicTaskTypeDesc.splice(0, dicTaskTypeDesc.length);
    taskDescByType.clear();
    let arr = readFileAndParse(FILENAME.DIC_TASK_TYPE);
    arr.forEach(o => {
        dicTaskTypeDesc.push(_.pick(o, Object.keys(DicTaskTypeKeys)));
        taskDescByType.set(o.id, _.pick(o, Object.keys(DicTaskTypeKeys)));
    });
    arr = undefined;
}