package com.ruoyi.enums;

import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;

@AllArgsConstructor
@Getter
public enum QuestionType {
    Single(1, "单选题"), Multiple(2, "多选题"), Judgment(3, "判断题"), Fill(4, "填空题"),
    Subjective(5, "主观题"), Short(6, "简答题"), Essay(7, "问答题"), Analysis(8, "分析题");

    private final Integer val;
    private final String title;

    private static final Map<String, QuestionType> valMap = Maps.newHashMap();

    public static QuestionType of(Integer vol) {
        return valMap.get(vol.toString());
    }

    public static QuestionType of(String vol) {
        QuestionType type = valMap.get(vol);
        return null == type ? QuestionType.Subjective : type;
    }

    static {
        Arrays.stream(QuestionType.values()).forEach(t -> {
            valMap.put(t.val.toString(), t);
            valMap.put(t.title, t);
            valMap.put(t.name(), t);
        });
    }
}
