package com.haha.common.enums;

import com.haha.common.vo.StatusLabel;

public enum CouponTypeEnum {

    FULL_REDUCTION(1, "满减券", "primary"),
    DISCOUNT(2, "折扣券", "success"),
    INSTANT_REDUCTION(3, "立减券", "warning"),
    PRODUCT(4, "商品券", "info");

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

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

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