package com.lesingle.edu.common.enums;

import lombok.Getter;

/**
 * 排课重复类型枚举
 */
@Getter
public enum ScheduleRepeatType {

    NONE("NONE", "不重复"),
    DAILY("DAILY", "每日"),
    WEEKLY("WEEKLY", "每周"),
    BIWEEKLY("BIWEEKLY", "双周");

    private final String code;
    private final String description;

    ScheduleRepeatType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据代码值转换为枚举
     */
    public static ScheduleRepeatType fromCode(String code) {
        if (code == null) {
            return NONE;
        }
        for (ScheduleRepeatType type : values()) {
            if (type.getCode().equalsIgnoreCase(code)) {
                return type;
            }
        }
        return NONE;
    }

    /**
     * 判断是否为有效的代码值
     */
    public static boolean isValidCode(String code) {
        if (code == null) {
            return false;
        }
        for (ScheduleRepeatType type : values()) {
            if (type.getCode().equalsIgnoreCase(code)) {
                return true;
            }
        }
        return false;
    }

}
