package com.haha.common.enums;

import com.haha.common.vo.StatusLabel;

/**
 * 奖励发放状态枚举
 */
public enum InviteRewardStatusEnum {

    /**
     * 待发放 - 等待发放
     */
    PENDING(0, "待发放", "warning"),

    /**
     * 已发放 - 发放成功
     */
    DISTRIBUTED(1, "已发放", "success"),

    /**
     * 发放失败 - 发放失败
     */
    FAILED(2, "发放失败", "danger"),

    /**
     * 已补发 - 手动补发成功
     */
    RETRIED(3, "已补发", "primary");

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

    InviteRewardStatusEnum(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);
    }

    /**
     * 根据code获取状态标签
     *
     * @param code 状态码
     * @return 状态标签
     */
    public static StatusLabel getLabelByCode(Integer code) {
        if (code == null) {
            return StatusLabel.info("未知");
        }
        for (InviteRewardStatusEnum status : values()) {
            if (status.code == code) {
                return status.getStatusLabel();
            }
        }
        return StatusLabel.info("未知");
    }

    /**
     * 根据code获取枚举对象
     *
     * @param code 状态码
     * @return 枚举对象，如果不存在返回null
     */
    public static InviteRewardStatusEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (InviteRewardStatusEnum status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        return null;
    }
}
