package com.muyu.common.core.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 类型枚举
 *
 * @Author: 胡杨
 * @Name: ClassType
 * @Description: 类型枚举
 * @CreatedDate: 2024/9/29 上午9:28
 * @FilePath: com.muyu.common.core.enums
 */

@Getter
public enum ClassType {
    BYTE("byte", byte.class),
    SHORT("short", short.class),
    INT("int", int.class),
    LONG("long", long.class),
    FLOAT("float", float.class),
    DOUBLE("double", double.class),
    BOOLEAN("boolean", boolean.class),
    CHAR("char", char.class),
    STRING("String", String.class),
    SET("Set", Set.class),
    MAP("Map", Map.class),
    LIST("List", List.class);

    private final String code;
    private final Class<?> info;

    ClassType(String code, Class<?> info) {
        this.code = code;
        this.info = info;
    }

    /**
     * 鉴别参数是否是枚举的值
     *
     * @param code 需鉴别参数
     * @return 如果存在返回结果turn, 否则返回false
     */
    public static boolean isCode(String code) {
        return Arrays.stream(values())
                .map(ClassType::getCode)
                .anyMatch(c -> c.equals(code));
    }


    public static Class<?> getInfo(String code) {
        return Arrays.stream(values())
                .filter(c -> c.getCode().equals(code))
                .findFirst()
                .map(ClassType::getInfo)
                .orElse(null);
    }
}
