
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 DefaultDbFieldEnum {

    ID("id", "id"),
    P_ID("pid", "pid"),
    CREATE_USER("create_user", "创建人"),
    CREATE_TIME("create_time", "创建时间"),
    CREATE_DEPT("create_dept", "创建部门"),
    IS_DELETED("is_deleted", "是否删除"),
    TENANT_ID("tenant_id", "租户id"),
    UPDATE_USER("update_user", "更新人"),
    UPDATE_TIME("update_time", "更新时间"),
    ;


    private final String fieldCode;
    private final String fieldName;


    public String getFieldCode() {
        return fieldCode;
    }

    public String getFieldName() {
        return fieldName;
    }

    DefaultDbFieldEnum(String fieldCode, String fieldName) {
        this.fieldCode = fieldCode;
        this.fieldName = fieldName;
    }

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

    }
}
