
package com.lideeyunji.tool.framework.yunji.enums;


import com.lideeyunji.tool.framework.yunji.utils.FuncBase;

import java.util.Arrays;
import java.util.Optional;

/**
 * 数据库类型-和前端对应
 */
public enum LideeYunJiFieldTypeEnum {

    STRING("String", "字符串"),
    INTEGER("Integer", "整数"),
    DATE("Date", "日期"),
    DATETIME("DateTime", "日期时间"),
    TIME("Time", "时间"),
    BIGINT("BigInt", "大整数"),
    BIGDECIMAL("BigDecimal", "小数"),
    TEXT("Text", "文本"),
    LONGTEXT("LongText", "大文本"),
    BLOB("Blob", "二进制");


    /**
     * Field类型
     */
    private final String fieldType;
    /**
     * 数据名称
     */
    private final String name;



    public String getFieldType() {
        return fieldType;
    }

    public String getName() {
        return name;
    }

    LideeYunJiFieldTypeEnum(String fieldType, String name) {
        this.fieldType = fieldType;
        this.name = name;
    }

    public static LideeYunJiFieldTypeEnum getByFieldType(String fieldType) {
        // 使用流来查找匹配的DbProductEnum
        Optional<LideeYunJiFieldTypeEnum> matchingEnum = Arrays.stream(LideeYunJiFieldTypeEnum.values())
                .filter(fieldTypeEnum -> FuncBase.equals(fieldTypeEnum.getFieldType(), fieldType))
                .findFirst(); // findFirst()会返回第一个匹配的元素，或者如果找不到则返回一个空的Optional
        // 检查是否找到了匹配的枚举项
        if (matchingEnum.isPresent()) {
            return matchingEnum.get();
        }
        return null;

    }
}
