package org.example.Entity.System;

import org.example.Utils.DataTableUtil;

import java.util.Map;
import java.util.Objects;

/**
 * 说明：
 * 创建时间：2018-12-29 11:12:05
 * 编辑人：
 * 编辑时间：
 * 备注：
 */
public class UpdStrModule {
    protected Map<String, Object> row;

    public static final String GuidKeyName = "fk";
    public static final String TableNameName = "bn";
    public static final String IdFieldName = "k";
    public static final String IdValueName = "v";
    public static final String IdentityIdName = "Id";

    private String idValue;
    private String identityId;

    public UpdStrModule(Map<String, Object> row) {
        this.row = row;
    }

    public String getGuidKey() {
        return DataTableUtil.get(row, GuidKeyName, "") + "";
    }

    public String getTableName() {
        return DataTableUtil.get(row, TableNameName, "") + "";
    }

    public String getIdField() {
        return DataTableUtil.get(row, IdFieldName, "") + "";
    }

    public String getIdValue() {
        if (idValue == null) {
            idValue = Objects.toString(DataTableUtil.get(row, IdValueName, ""), "");
        }
        return idValue;
    }

    public void setIdValue(String idValue) {
        this.idValue = idValue;
    }

    public String getIdentityId() {
        if (identityId == null) {
            identityId = DataTableUtil.get(row, IdentityIdName, "") + "";
        }
        return identityId;
    }

    public void setIdentityId(String identityId) {
        this.identityId = identityId;
    }

    public boolean Valide() {
        return !isBlank(getGuidKey()) &&
                !isBlank(getTableName()) &&
                !isBlank(getIdField()) &&
                !(isBlank(getIdValue()) && isBlank(getIdentityId()));
    }

    // 工具方法：判断字符串是否为空白（null或空字符串）
    private boolean isBlank(String str) {
        return str == null || str.trim().isEmpty();
    }
}