/*
 * *************************************************
 * Copyright (c) 2018 QMTH. All Rights Reserved.
 * Created by Deason on 2018-07-12 15:31:09.
 * *************************************************
 */

package cn.com.qmth.examcloud.core.questions.base.converter.model;

public enum QuesStructType {
    SINGLE_ANSWER_QUESTION(1, "单选题", true, false),
    MULTIPLE_ANSWER_QUESTION(2, "多选题", true, false),
    BOOL_ANSWER_QUESTION(3, "判断题", true, false),
    FILL_BLANK_QUESTION(4, "填空题", false, false),
    TEXT_ANSWER_QUESTION(5, "问答题", false, false),
    NESTED_ANSWER_QUESTION(6, "套题", false, true);

    private int id;
    private String name;
    private boolean objective;//是否是客观题
    private boolean combine;//是否是组合题

    QuesStructType(int id, String name, boolean objective, boolean combine) {
        this.id = id;
        this.name = name;
        this.objective = objective;
        this.combine = combine;
    }

    /**
     * 通过ID获取试题类型
     */
    public static QuesStructType getTypeById(Integer id) {
        if (id == null) {
            return null;
        }
        for (QuesStructType type : QuesStructType.values()) {
            if (id.equals(type.getId())) {
                return type;
            }
        }
        return null;
    }

    /**
     * 通过名称获取试题类型
     */
    public static QuesStructType getTypeByName(String name) {
        if (name == null) {
            return null;
        }
        for (QuesStructType type : QuesStructType.values()) {
            if (type.getName().equals(name)) {
                return type;
            }
        }
        return null;
    }

    /**
     * 根据ID判断是否为客观题
     */
    public static boolean isObjective(Integer id) {
        if (id == null) {
            return false;
        }
        for (QuesStructType type : QuesStructType.values()) {
            if (id.equals(type.getId())) {
                return type.objective;
            }
        }
        return false;
    }

    /**
     * 根据名称判断是否为客观题
     */
    public static boolean isObjective(String name) {
        if (name == null) {
            return false;
        }
        for (QuesStructType type : QuesStructType.values()) {
            if (type.getName().equals(name)) {
                return type.objective;
            }
        }
        return false;
    }

    /**
     * 根据ID判断是否为套题
     */
    public static boolean isCombine(Integer id) {
        if (id == null) {
            return false;
        }

        for (QuesStructType type : QuesStructType.values()) {
            if (id.equals(type.getId())) {
                return type.combine;
            }
        }
        return false;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public boolean isObjective() {
        return objective;
    }

    public boolean isCombine() {
        return combine;
    }

    public String toString() {
        return getName();
    }

}