package com.lesingle.edu.common.enums;

import lombok.Getter;

/**
 * 排课状态枚举
 */
@Getter
public enum ScheduleStatus {

    ACTIVE("ACTIVE", "有效"),
    SCHEDULED("SCHEDULED", "已排期"),
    CANCELLED("CANCELLED", "已取消");

    private final String code;
    private final String description;

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

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

    /**
     * 判断是否为有效/激活状态
     */
    public static boolean isActive(String status) {
        if (status == null) {
            return false;
        }
        return ACTIVE.getCode().equalsIgnoreCase(status) ||
               SCHEDULED.getCode().equalsIgnoreCase(status);
    }

    /**
     * 判断是否为已取消状态
     */
    public static boolean isCancelled(String status) {
        if (status == null) {
            return false;
        }
        return CANCELLED.getCode().equalsIgnoreCase(status);
    }

    /**
     * 判断当前状态是否为激活状态
     */
    public boolean isActive() {
        return this == ACTIVE || this == SCHEDULED;
    }

    /**
     * 判断当前状态是否为已取消状态
     */
    public boolean isCancelled() {
        return this == CANCELLED;
    }

}
