
package com.ruoyi.course.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.annotation.IEnum;
import lombok.Getter;

@Getter
public enum GradeEnum implements IEnum<Integer> {
    ALL(0, "全部"),
    FRESHMAN(1, "高一"),
    SOPHOMORE(2, "高二"),
    JUNIOR(3, "高三");
    // 未来扩展：SENIOR(4, "高四")

    @EnumValue  // MyBatis-Plus 注解，告诉框架存这个值到数据库
    private final int code;

    private final String displayName;

    GradeEnum(int code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    /**
     * 根据code获取枚举
     */
    public static GradeEnum fromCode(int code) {
        for (GradeEnum grade : GradeEnum.values()) {
            if (grade.getCode() == code) {
                return grade;
            }
        }
        throw new IllegalArgumentException("无效的年级代码: " + code);
    }

    /**
     * 根据显示名称获取枚举
     */
    public static GradeEnum fromDisplayName(String displayName) {
        for (GradeEnum grade : GradeEnum.values()) {
            if (grade.getDisplayName().equals(displayName)) {
                return grade;
            }
        }
        throw new IllegalArgumentException("无效的年级名称: " + displayName);
    }

    /**
     * 获取排序值
     */
    public int getOrder() {
        return this.code;
    }


    @Override
    public Integer getValue() {
        return this.getCode();
    }
}