package com.haha.common.enums;

public enum DeviceDoorStatus {

    ERROR("1", "error", "开门失败"),
    OPENED("2", "open", "门已开"),
    CLOSED("3", "close", "门已关"),
    BUSY("4", "busy", "设备繁忙");

    private final String code;
    private final String status;
    private final String description;

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

    public String getCode() {
        return code;
    }

    public String getStatus() {
        return status;
    }

    public String getDescription() {
        return description;
    }

    public static DeviceDoorStatus fromCode(String code) {
        if (code == null) {
            return null;
        }
        for (DeviceDoorStatus doorStatus : values()) {
            if (doorStatus.code.equals(code)) {
                return doorStatus;
            }
        }
        return null;
    }

    public static String convertToStatus(String code) {
        DeviceDoorStatus doorStatus = fromCode(code);
        return doorStatus != null ? doorStatus.getStatus() : "unknown";
    }
}
