package com.haha.common.enums;

import com.haha.common.vo.StatusLabel;

public enum DistributeTypeEnum {

    USER_RECEIVE(1, "主动领取", "primary"),
    SYSTEM_SEND(2, "系统发放", "success"),
    TARGET_SEND(3, "定向发放", "warning");

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

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

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