package com.fuyuanshen.global.mqtt.listener.domain;

/**
 * 功能访问状态枚举
 */
public enum FunctionAccessStatus {
    
    /**
     * 失败状态
     */
    FAILED("FAILED", "失败"),
    
    /**
     * 成功状态
     */
    OK("OK", "成功"),

    /**
     * 激活中状态
     */
    ACTIVE("ACTIVE", "处理中"),

    /**
     * 超时状态
     */
    TIMEOUT("TIMEOUT", "超时");

    private final String code;
    private final String description;

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

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取状态枚举
     * @param code 状态代码
     * @return 对应的状态枚举
     */
    public static FunctionAccessStatus fromCode(String code) {
        for (FunctionAccessStatus status : FunctionAccessStatus.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("未知的状态代码: " + code);
    }

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