package com.ruoyi.common.enums;

import java.util.HashMap;
import java.util.Map;

public enum SubjectType {
    Physics("物理", "物"), History("历史", "历"), Chemistry("化学", "化"), Biology("生物", "生"), Geography("地理", "地"), Political("政治", "政"),
    Chinese("语文", "语"), Mathematics("数学", "数"), English("英语", "英"), Foreign("外语", "外");

    public String title() {
        return title;
    }

    public static SubjectType parse(String name) {
        SubjectType st = map.get(name);
        if(null == st) {
            throw new RuntimeException("Invalid SubjectType " + name);
        }
        return map.get(name.toLowerCase());
    }

    private final String title;
    private final String abbr;
    SubjectType(String title, String abbr) {
        this.title = title;
        this.abbr = abbr;
    }

    private static Map<String, SubjectType> map = new HashMap<>();
    static {
        for(SubjectType type : SubjectType.values()) {
            map.put(type.title, type);
            map.put(type.abbr, type);
            map.put(type.name().toLowerCase(), type);
        }
    }
}
