package com.haha.common.enums;

import com.haha.common.vo.StatusLabel;
import lombok.Getter;

/**
 * 分销员状态枚举
 */
@Getter
public enum DistributorStatus {

    PENDING(0, "待激活", "info"),
    ACTIVE(1, "已激活", "success"),
    DISABLED(2, "已停用", "danger");

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

    DistributorStatus(int code, String label, String color) {
        this.code = code;
        this.label = label;
        this.color = color;
    }

    public StatusLabel getStatusLabel() {
        return new StatusLabel(label, color);
    }

    public static StatusLabel getLabelByCode(Integer code) {
        if (code == null) {
            return StatusLabel.info("未知");
        }
        for (DistributorStatus status : values()) {
            if (status.code == code) {
                return status.getStatusLabel();
            }
        }
        return StatusLabel.info("未知");
    }

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

    public static boolean isPending(Integer code) {
        return code != null && code == PENDING.code;
    }

    public static boolean isActive(Integer code) {
        return code != null && code == ACTIVE.code;
    }
}
