package com.haha.common.enums;

import com.haha.common.vo.StatusLabel;

public enum TargetTypeEnum {

    ALL_USER(1, "全部用户", "primary"),
    NEW_USER(2, "新用户", "success"),
    SPECIFIED_USER(3, "指定用户", "warning");

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

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

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