package cn.stylefeng.team.meta.sdk.parser;

import cn.stylefeng.team.meta.api.enums.MetaFieldTypeEnum;
import lombok.Getter;

@Getter
public enum MetaFieldTypeToJavaType {

    VARCHAR(MetaFieldTypeEnum.NORMAL_STR.getCode(), "String"),

    ONE_CHAR(MetaFieldTypeEnum.FIXED_STR.getCode(), "String"),

    TEXT(MetaFieldTypeEnum.LONG_STR.getCode(), "String"),

    INT(MetaFieldTypeEnum.INT.getCode(), "Integer"),

    BIGINT(MetaFieldTypeEnum.BIGINT.getCode(), "Long"),

    DECIMAL(MetaFieldTypeEnum.DECIMAL.getCode(), "BigDecimal"),

    DATETIME(MetaFieldTypeEnum.DATE_TIME.getCode(), "Date"),

    DATE(MetaFieldTypeEnum.DATE.getCode(), "Date"),

    TIME(MetaFieldTypeEnum.TIME.getCode(), "Date"),

    JSON(MetaFieldTypeEnum.OBJECT.getCode(), "JSONObject"),

    LIST(MetaFieldTypeEnum.LIST.getCode(), "JSONArray"),

    BYTES(MetaFieldTypeEnum.BYTES.getCode(), "byte[]");

    private final Integer metaType;

    private final String javaType;

    MetaFieldTypeToJavaType(Integer metaType, String javaType) {
        this.metaType = metaType;
        this.javaType = javaType;
    }

    public static String getJavaType(Integer metaType) {
        for (MetaFieldTypeToJavaType value : MetaFieldTypeToJavaType.values()) {
            if (value.getMetaType().equals(metaType)) {
                return value.getJavaType();
            }
        }
        return null;
    }

}
