package org.example.Entity.System;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.example.Entity.Control.Base.Component;
import org.example.Enums.SystemTypeEnums;
import org.example.Utils.PublicUtil;

import java.util.Map;

import static org.example.Utils.DataTableUtil.get;
import static org.example.Utils.NativeExtensionUtils.ToInt32;

public class BillSourceModule {
    protected Map<String, Object> _row;

    public BillSourceModule() {
    }

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

    private Integer _sourceId;

    @JsonProperty("SourceId")
    public int getSourceId() {
        return ToInt32(get(_row, "id", _sourceId, null));
    }

    public void setSourceId(int sourceId) {
        this._sourceId = sourceId;
    }

    private String moduleId;

    @JsonProperty("ModuleId")
    public String getModuleId() {
        return moduleId;
    }

    public void setModuleId(String moduleId) {
        this.moduleId = moduleId;
    }

    private String _idField;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonProperty("IdField")
    public String getIdField() {
        _idField = (String) get(_row, "sourcekeyfield", _idField, null);
        if (_idField != null && !_idField.isEmpty()) {
            return _idField.toLowerCase();
        }
        return _idField;
    }

    public void setIdField(String idField) {
        this._idField = idField;
    }

    private String _displayField;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonProperty("DisplayField")
    public String getDisplayField() {
        _displayField = (String) get(_row, "sourceresult", _displayField, null);
        if (_displayField != null && !_displayField.isEmpty()) {
            return _displayField.toLowerCase();
        }
        return _displayField;
    }

    public void setDisplayField(String displayField) {
        this._displayField = displayField;
    }

    private String _title;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonProperty("Title")
    public String getTitle() {
        return (String) get(_row, "username", _title, null);
    }

    public void setTitle(String title) {
        this._title = title;
    }

    private int _sourceType;

    @JsonProperty("SourceType")
    public int getSourceType() {
        return ToInt32(get(_row, "sourcetype", 0));
    }

    public void setSourceType(int sourceType) {
        this._sourceType = sourceType;
    }

    private String _masterSql;

    @JsonIgnore
    @JsonProperty("MasterSql")
    public String getMasterSql() {
        return (String) get(_row, "sourcesql", _masterSql, null);
    }

    public void setMasterSql(String masterSql) {
        this._masterSql = masterSql;
    }

    private String _detailSql;

    @JsonIgnore
    @JsonProperty("DetailSql")
    public String getDetailSql() {
        return (String) get(_row, "detailsql", _detailSql, null);
    }

    public void setDetailSql(String detailSql) {
        this._detailSql = detailSql;
    }

    private String _detailEnableCond;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonProperty("DetailEnableCond")
    public String getDetailEnableCond() {
        if (_detailEnableCond == null) {
            _detailEnableCond = (String) get(_row, "DetailEnableCond", _detailEnableCond, null);
        }
        _detailEnableCond = PublicUtil.ReqSqlPmsByRow(
                null,
                null,
                PublicUtil.SqlToCode(_detailEnableCond),
                SystemTypeEnums.PmType.ignorenull
        );
        return _detailEnableCond;
    }

    public void setDetailEnableCond(String detailEnableCond) {
        this._detailEnableCond = detailEnableCond;
    }

    private String _detailEnableMsg;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonProperty("DetailEnableMsg")
    public String getDetailEnableMsg() {
        return (String) get(_row, "DetailEnableMsg", _detailEnableMsg, null);
    }

    public void setDetailEnableMsg(String detailEnableMsg) {
        this._detailEnableMsg = detailEnableMsg;
    }

    private String _fromkey;

    @JsonIgnore
    @JsonProperty("Fromkey")
    public String getFromkey() {
        Object fk = get(_row, "fromkey", _fromkey, null);
        if (fk != null && !String.valueOf(fk).isEmpty()) {
            _fromkey = String.valueOf(fk);
            return _fromkey;
        }
        return null;
    }

    public void setFromkey(String fromkey) {
        this._fromkey = fromkey;
    }

    private Object tbarItems;

    @JsonProperty("TbarItems")
    public Object getTbarItems() {
        return tbarItems;
    }

    public void setTbarItems(Object tbarItems) {
        this.tbarItems = tbarItems;
    }

    /**
     * 基础档案右边结构
     */

    private Component main;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonProperty("Main")
    public Component getMain() {
        return main;
    }

    public void setMain(Component main) {
        this.main = main;
    }

    /**
     * 明细
     */

    private Object details;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonProperty("Details")
    public Object getDetails() {
        return details;
    }

    public void setDetails(Object details) {
        this.details = details;
    }
}

