package com.haha.common.enums;

import com.haha.common.vo.StatusLabel;

public enum ExecuteStatusEnum {

    SUCCESS(1, "成功", "success"),
    PARTIAL_SUCCESS(2, "部分成功", "warning"),
    FAILED(3, "失败", "danger");

    private final int code;
    private final String label;
    private final String color;

    ExecuteStatusEnum(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 (ExecuteStatusEnum status : values()) {
            if (status.code == code) {
                return status.getStatusLabel();
            }
        }
        return StatusLabel.info("未知");
    }

    public static ExecuteStatusEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (ExecuteStatusEnum status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        return null;
    }
}
