package cn.iocoder.yudao.module.mes.controller.admin.plan.vo;

/**
 * 星期枚举 - 简单版
 * 对应 MySQL DAYOFWEEK() 函数返回值
 */
public enum WeekDayEnum {

    SUNDAY(1, "周日"),
    MONDAY(2, "周一"),
    TUESDAY(3, "周二"),
    WEDNESDAY(4, "周三"),
    THURSDAY(5, "周四"),
    FRIDAY(6, "周五"),
    SATURDAY(7, "周六");

    private final int code;
    private final String name;

    // 静态映射表
    private static final WeekDayEnum[] VALUES = values();

    WeekDayEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public int getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    /**
     * 根据 DAYOFWEEK() 返回值获取星期名称
     */
    public static String getNameByCode(int code) {
        for (WeekDayEnum day : VALUES) {
            if (day.code == code) {
                return day.name;
            }
        }
        return "未知";
    }

    /**
     * 根据 DAYOFWEEK() 返回值获取枚举
     */
    public static WeekDayEnum getByCode(int code) {
        for (WeekDayEnum day : VALUES) {
            if (day.code == code) {
                return day;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return name;
    }

}
