package com.fjhx.common.enums;

import com.ruoyi.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum RuleTypeEnum {

    CUSTOMIZE(1, "自定义字符"),
    COUNTRY_CODE(2, "客户国家编码"),
    SALESMAN_CODE(3, "业务员代码"),
    CUSTOMER_CODE(4, "客户编码"),
    AUTOINCREMENT(5, "自增编号"),
    DATE_FORMAT(6, "日期");

    private final Integer type;

    private final String name;

    private static final Map<Integer, RuleTypeEnum> map = new HashMap<>();

    static {
        for (RuleTypeEnum value : RuleTypeEnum.values()) {
            map.put(value.getType(), value);
        }
    }

    public static RuleTypeEnum getRuleTypeEnum(Integer type) {
        RuleTypeEnum ruleTypeEnum = map.get(type);
        if (ruleTypeEnum == null) {
            throw new ServiceException("编码规则类型不存在");
        }
        return ruleTypeEnum;
    }

}
