package com.haha.common.enums;

import com.haha.common.vo.StatusLabel;

import java.util.HashMap;
import java.util.Map;

/**
 * 通用状态枚举
 * 用于各种实体的状态标识
 */
public enum CommonStatus {
    
    /**
     * 启用/正常
     */
    ENABLED(1, "启用", "success"),
    
    /**
     * 禁用
     */
    DISABLED(0, "禁用", "danger");
    
    private final int code;
    private final String label;
    private final String color;
    
    CommonStatus(int code, String label, String color) {
        this.code = code;
        this.label = label;
        this.color = color;
    }
    
    public int getCode() {
        return code;
    }
    
    public String getLabel() {
        return label;
    }
    
    public String getColor() {
        return color;
    }
    
    /**
     * 获取状态标签
     */
    public StatusLabel getStatusLabel() {
        return new StatusLabel(label, color);
    }
    
    /**
     * 根据状态码获取标签
     */
    public static StatusLabel getLabelByCode(Integer code) {
        if (code == null) {
            return StatusLabel.info("未知");
        }
        for (CommonStatus status : values()) {
            if (status.code == code) {
                return status.getStatusLabel();
            }
        }
        return StatusLabel.info("未知");
    }
    
    /**
     * 判断是否为启用状态
     */
    public static boolean isEnabled(Integer status) {
        return status != null && status == ENABLED.code;
    }
}
