package com.ylx.order.enums;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;

@Getter
public enum CustomerTagEnum {
    NEW_CUSTOMER(0, "新客收单"),
    REPURCHASE(1, "再次复购"),
    OLD_CUSTOMER(2, "老客户");

    private final Integer code;
    private final String desc;

    CustomerTagEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 根据code获取枚举
     */
    public static CustomerTagEnum getByCode(Integer code) {
        if (ObjectUtil.isNull(code)) {
            return null;
        }
        for (CustomerTagEnum tag : values()) {
            if (tag.getCode().equals(code)) {
                return tag;
            }
        }
        return null;
    }

    /**
     * 根据code获取展示文案
     */
    public static String getDescByCode(Integer code) {
        CustomerTagEnum tagEnum = getByCode(code);
        return ObjectUtil.isNotNull(tagEnum) ? tagEnum.getDesc() : null;
    }

}
