package com.lesingle.edu.common.enums;

import lombok.Getter;

/**
 * 教师活跃度等级枚举
 * 根据统计周期内的授课次数划分活跃程度
 */
@Getter
public enum TeacherActivityLevel {

    /**
     * 高频活跃：统计周期内授课次数 >= 10 次
     */
    HIGH("HIGH", "高频", 10),

    /**
     * 中频活跃：统计周期内授课次数 5-9 次
     */
    MEDIUM("MEDIUM", "中频", 5),

    /**
     * 低频活跃：统计周期内授课次数 1-4 次
     */
    LOW("LOW", "低频", 1),

    /**
     * 未活跃：统计周期内授课次数为 0 次
     */
    INACTIVE("INACTIVE", "未活跃", 0);

    private final String code;
    private final String description;
    private final int minLessonCount;

    TeacherActivityLevel(String code, String description, int minLessonCount) {
        this.code = code;
        this.description = description;
        this.minLessonCount = minLessonCount;
    }

    /**
     * 根据授课次数获取活跃度等级
     *
     * @param lessonCount 授课次数
     * @return 活跃度等级
     */
    public static TeacherActivityLevel fromLessonCount(int lessonCount) {
        if (lessonCount >= HIGH.minLessonCount) {
            return HIGH;
        } else if (lessonCount >= MEDIUM.minLessonCount) {
            return MEDIUM;
        } else if (lessonCount >= LOW.minLessonCount) {
            return LOW;
        } else {
            return INACTIVE;
        }
    }

    /**
     * 根据编码获取活跃度等级
     *
     * @param code 编码
     * @return 活跃度等级
     */
    public static TeacherActivityLevel fromCode(String code) {
        for (TeacherActivityLevel level : values()) {
            if (level.getCode().equals(code)) {
                return level;
            }
        }
        return INACTIVE;
    }
}
