package com.seer.teach.common.enums.teacher;

import java.util.Arrays;

/**
 * 学习类型枚举
 * <p>
 * 用于区分不同的学习模式，例如：
 * 0 - 批改
 * 1 - 复习
 * 2 - 预习
 * 3 - 黑马计划
 * 4 - 测评
 *
 * @author Captain
 * @since 2025-05-09
 */
public enum ModuleEnum {

    AI_CORRECT(0, "批改"),
    LESSON(1, "学堂"),
    REVIEW(1, "复习"),
    PREVIEW(2, "预习"),
    PLAN(3, "黑马计划"),
    EVALUATION(4, "测评"),
    SMART_READING(5, "智读"),
    TREASURE_CHESTS_READING(6, "智读");

    private final int code;

    private final String msg;

    ModuleEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    /**
     * 根据 code 获取对应枚举
     *
     * @param code 数值类型
     * @return 对应的 StudyEnum；如果未匹配则返回 null
     */
    public static ModuleEnum fromCode(Integer code) {
        if (code == null) {
            return null;
        }
        return Arrays.stream(values())
                .filter(e -> e.code == code)
                .findFirst()
                .orElse(null);
    }

    @Override
    public String toString() {
        return String.format("%s(%d - %s)", this.name(), code, msg);
    }
}
