package org.example.Entity.Control.Com;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.example.Entity.Control.Base.RowComponent;
import org.example.Utils.DataTableUtil;
import org.example.Utils.IPublicUtil;

import java.util.Map;

import static org.example.Utils.NativeExtensionUtils.toBoolean;

/**
 * ==============================================================================
 * 功能描述：Button
 * ==============================================================================
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Button extends RowComponent {

    public Button() {
        super(null);
        this.defaultXtype = "button";
    }

    public Button(Map<String, Object> row) {
        super(row);
        this.defaultXtype = "button";
        this._row = row;
    }

    public Button(Map<String, Object> row, IPublicUtil util) {
        super(row, util);
        this.defaultXtype = "button";
        this._row = row;
        this.setUtil(util);
    }

    private int toolId;
    private String cls;
    private String iconCls;
    private String text;

    private Boolean hidden;
    private String actionLib;
    private String action;
    private String beforeMsg;
    private String successMsg;
    private String errorMsg;
    private String handler;
    private boolean formBind;
    private Object menu;
    private String href;
    private String pm1;
    private String pm2;
    private String pm3;
    private String pm4;
    private String pm5;
    private String pm6;
    private String pm7;
    private String pm8;
    private String pm9;
    private String pm10;

    // 工具ID
    public int getToolId() {
        if (toolId <= 0 && _row != null) {
            toolId = DataTableUtil.getIntValue(_row, "id", 0);
        }
        return toolId;
    }

    public void setToolId(int toolId) {
        this.toolId = toolId;
    }

    // CSS类
    public String getCls() {
        return cls;
    }

    public void setCls(String cls) {
        this.cls = cls;
    }

    // 图标类
    public String getIconCls() {
        return iconCls;
    }

    public void setIconCls(String iconCls) {
        this.iconCls = iconCls;
    }

    // 按钮文本
    public String getText() {
        if (text == null && _row != null) {
            text = DataTableUtil.getStringValue(_row, new String[]{"menucaption", "text"}, null);
        }
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    private String _recordCond;

    // 记录条件
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonProperty("RecordCond")
    public String getRecordCond() {
        if (_recordCond == null && _row != null) {
            _recordCond = (String) DataTableUtil.getRowVal(_row, "Menucond", null);
        }
        return _recordCond;
    }

    public void setRecordCond(String recordCond) {
        this._recordCond = recordCond;
    }

    // 隐藏状态

    public Boolean getHidden() {
        return hidden;
    }


    public void setHidden(Boolean hidden) {
        this.hidden = hidden;
    }

    // 按钮类型
    @JsonProperty("BType")
    public int getBType() {
        return _row != null ? DataTableUtil.getIntValue(_row, "type", 0) : 0;
    }

    // 动作类型
    @JsonProperty("ActionType")
    public int getActionType() {
        return _row != null ? DataTableUtil.getIntValue(_row, "actiontype", 0) : 0;
    }

    @JsonIgnore    // 动态链接库
    public String getActionLib() {
        if (actionLib == null && _row != null) {
            actionLib = DataTableUtil.getStringValue(_row, "library", null);
        }
        return actionLib;
    }

    public void setActionLib(String actionLib) {
        this.actionLib = actionLib;
    }


    @JsonIgnore
    // 执行的SQL或存储过程
    public String getAction() {
        if (action == null && _row != null) {
            action = DataTableUtil.getStringValue(_row, "action", null);
        }
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    // 执行前提示
    public String getBeforeMsg() {
        if (beforeMsg == null && _row != null) {
            beforeMsg = DataTableUtil.getStringValue(_row, "beforemsg", null);
        }
        return beforeMsg;
    }

    public void setBeforeMsg(String beforeMsg) {
        this.beforeMsg = beforeMsg;
    }

    // 执行成功提示
    public String getSuccessMsg() {
        if (successMsg == null && _row != null) {
            successMsg = DataTableUtil.getStringValue(_row, "SuccessMsg", null);
        }
        return successMsg;
    }

    public void setSuccessMsg(String successMsg) {
        this.successMsg = successMsg;
    }

    // 执行失败提示
    public String getErrorMsg() {
        if (errorMsg == null && _row != null) {
            errorMsg = DataTableUtil.getStringValue(_row, "ErrorMsg", null);
        }
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    // 双击属性
    @JsonProperty("DoubleClick")
    public boolean isDoubleClick() {
        return _row != null && DataTableUtil.getBooleanValue(_row, "DoubleClick", false);
    }

    // 窗口最大化
    @JsonProperty("MaxWindow")
    public boolean isMaxWindow() {
        return _row != null && DataTableUtil.getBooleanValue(_row, "MaxWindow", false);
    }

    // 执行后刷新
    @JsonProperty("Refresh")
    public boolean isRefresh() {
        return toBoolean(DataTableUtil.getRowVal(_row, "Refresh", false));
    }

    // 多选
    @JsonProperty("MoreClick")
    public boolean isMoreClick() {
        return _row != null && DataTableUtil.getBooleanValue(_row, "moreclick", false);
    }

    // 多选提示
    @JsonProperty("MoreClickTip")
    public boolean isMoreClickTip() {
        return _row != null && DataTableUtil.getBooleanValue(_row, "moreclicktip", false);
    }

    // 处理函数
    public String getHandler() {
        return handler;
    }

    public void setHandler(String handler) {
        this.handler = handler;
    }

    // 表单绑定
    public boolean isFormBind() {
        return formBind;
    }

    public void setFormBind(boolean formBind) {
        this.formBind = formBind;
    }

    // 菜单
    public Object getMenu() {
        return menu;
    }

    public void setMenu(Object menu) {
        this.menu = menu;
    }

    // 链接
    public String getHref() {
        return href;
    }

    public void setHref(String href) {
        this.href = href;
    }

    // 刷新标志
    @JsonProperty("refresh")
    public boolean isLowerRefresh() {
        return toBoolean(DataTableUtil.getRowVal(this._row, "refresh", true));
    }

    // 参数1-10的实现
    public String getPm1() {
        if (pm1 == null && _row != null) {
            pm1 = DataTableUtil.getStringValue(_row, "param1", null);
        }
        return pm1;
    }

    public void setPm1(String pm1) {
        this.pm1 = pm1;
    }

    public String getPm2() {
        if (pm2 == null && _row != null) {
            pm2 = DataTableUtil.getStringValue(_row, "param2", null);
        }
        return pm2;
    }

    public void setPm2(String pm2) {
        this.pm2 = pm2;
    }

    public String getPm3() {
        if (pm3 == null && _row != null) {
            pm3 = DataTableUtil.getStringValue(_row, "param3", null);
        }
        return pm3;
    }

    public void setPm3(String pm3) {
        this.pm3 = pm3;
    }

    public String getPm4() {
        if (pm4 == null && _row != null) {
            pm4 = DataTableUtil.getStringValue(_row, "param4", null);
        }
        return pm4;
    }

    public void setPm4(String pm4) {
        this.pm4 = pm4;
    }

    public String getPm5() {
        if (pm5 == null && _row != null) {
            pm5 = DataTableUtil.getStringValue(_row, "param5", null);
        }
        return pm5;
    }

    public void setPm5(String pm5) {
        this.pm5 = pm5;
    }

    public String getPm6() {
        if (pm6 == null && _row != null) {
            pm6 = DataTableUtil.getStringValue(_row, "param6", null);
        }
        return pm6;
    }

    public void setPm6(String pm6) {
        this.pm6 = pm6;
    }

    public String getPm7() {
        if (pm7 == null && _row != null) {
            pm7 = DataTableUtil.getStringValue(_row, "param7", null);
        }
        return pm7;
    }

    public void setPm7(String pm7) {
        this.pm7 = pm7;
    }

    public String getPm8() {
        if (pm8 == null && _row != null) {
            pm8 = DataTableUtil.getStringValue(_row, "param8", null);
        }
        return pm8;
    }

    public void setPm8(String pm8) {
        this.pm8 = pm8;
    }

    public String getPm9() {
        if (pm9 == null && _row != null) {
            pm9 = DataTableUtil.getStringValue(_row, "param9", null);
        }
        return pm9;
    }

    public void setPm9(String pm9) {
        this.pm9 = pm9;
    }

    public String getPm10() {
        if (pm10 == null && _row != null) {
            pm10 = DataTableUtil.getStringValue(_row, "param10", null);
        }
        return pm10;
    }

    public void setPm10(String pm10) {
        this.pm10 = pm10;
    }
}