package com.tuoheng.admin.enums;

import lombok.Getter;

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

/**
 * client 枚举类
 *
 * @Author xiaoying
 * @Date 2022/11/25 16:51
 */
public enum ClientEnum {

    ADMIN(1, "tuoheng-freeway-admin"),
    MP(2, "tuoheng-freeway-mp");

    ClientEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    @Getter
    private int code;

    @Getter
    private String description;

    private static Map<Integer, ClientEnum> data = new HashMap<>();

    static {
        for (ClientEnum type : ClientEnum.values()) {
            data.put(type.code, type);
        }
    }

    public static ClientEnum parse(int code) {
        if (data.containsKey(code)) {
            return data.get(code);
        }
        return null;
    }

    public static ClientEnum parse(String description) {
        ClientEnum[] valueEnums = values();
        for (ClientEnum valueEnum : valueEnums) {
            if (valueEnum.getDescription().equals(description)) {
                return valueEnum;
            }
        }
        return null;
    }
}
