package com.haha.common.enums;

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

/**
 * 分销推荐状态枚举
 */
@Getter
public enum DistributorReferralStatus {

    PENDING(0, "待生效", "info"),
    ACTIVE(1, "有效", "success"),
    EXPIRED(2, "已过期", "warning");

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

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

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