package cn.edu.whu.boot.xml.xmlreader.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Li Bozhao
 */
public class Field  implements Serializable {
    private static final long serialVersionUID = -8992769078483751487L;//,Cloneable
    private String key;//字段名称*
    private String viewKey;//这个用于索引，比如在associate中这个的key就应该带着检索名称，格式为表.字段
    private String dbType;//数据类型
    private String name;//显示的中文名称
    private String type;//组件名称
    private String mode;//组件模式
    private String resultType;//对于单选、多选、下拉框啥的，是返回value还是返回key
    private String script;//脚本
    private String show;//是否可见 可以输入脚本表达式
    private boolean parentID;//用于子表格关联父表格中的ID
    private String autoDate;//默认为"yyyyMMddYYmmss"
    private String associate;//*
    private String collection;//*
    private int index;
    private boolean enable = true;//是否可用
    private boolean identity;//是否主键*
    private boolean autoIncrement;//是否自增长
    private boolean geometry;//是否是空间对象*
    private boolean zipField;
    private boolean uploadName;
    private boolean required;
    private String tooltips;//工具使用注释
    private String check;
    /*可分组的选项*/
    private String select;//控制Select的脚本
    private String lastSelectValue;//记录当前select的值，如果不记录可能会导致循环不止
    private Map<String, Select> selects = new HashMap<>();//固定显示的选项
    private Map<String, Group> groups = new HashMap<>();//由select控制的选项分组
    private List<Select> showSelects = new ArrayList<>();//用于显示的列表

    private Object value;//*
    private Map<String,Field> collectionValue;//仅用于collection在autoform中的双向绑定

    public String getKey() {
        return key;
    }
    public String getTooltips() {
        return tooltips;
    }
    public  void setTooltips(String tooltips ){ this.tooltips= tooltips ;}
    public String getCheck() {
        return check;
    }
    public  void setCheck(String check){ this.check= check ;}
    public void setKey(String key) {
        this.key = key;
    }

    public String getDbType() {
        return dbType;
    }

    public void setDbType(String dbType) {
        this.dbType = dbType;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getResultType() {
        return resultType;
    }

    public void setResultType(String resultType) {
        this.resultType = resultType;
    }

    public String getScript() {
        return script;
    }

    public void setScript(String script) {
        this.script = script;
    }

    public String getShow() {
        return show;
    }

    public void setShow(String show) {
        this.show = show;
    }

//    public boolean getParentID() {
//        return parentID;
//    }

    public void setParentID(boolean parentID) {
        this.parentID = parentID;
    }

    public boolean isParentID() {
        return parentID;
    }

    public String getAutoDate() {
        return autoDate;
    }

    public void setAutoDate(String autoDate) {
        this.autoDate = autoDate;
    }

    public boolean isEnable() {
        return enable;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    public boolean isIdentity() {
        return identity;
    }

    public void setIdentity(boolean identity) {
        this.identity = identity;
    }

    public boolean isAutoIncrement() {
        return autoIncrement;
    }

    public void setAutoIncrement(boolean autoIncrement) {
        this.autoIncrement = autoIncrement;
    }

    public String getAssociate() {
        return associate;
    }

    public void setAssociate(String associate) {
        this.key = associate;
        this.associate = associate;
    }

    public String getCollection() {
        return collection;
    }

    public void setCollection(String collection) {
        this.key = collection;
        this.collection = collection;
    }

    public String getSelect() {
        return select;
    }

    public void setSelect(String select) {
        this.select = select;
    }

    public Map<String, Select> getSelects() {
        return selects;
    }

    public void setSelects(Map<String, Select> selects) {
        this.selects = selects;
    }

    public void addSelect(Select select){
        this.selects.put(select.getKey(),select);
    }

    public void addGroup(Group group){
        this.groups.put(group.getKey(),group);
    }

    public Map<String, Group> getGroups() {
        return groups;
    }

    public void setGroups(Map<String, Group> groups) {
        this.groups = groups;
    }

    public boolean isGeometry() {
        return geometry;
    }

    public void setGeometry(boolean geometry) {
        this.geometry = geometry;
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        if(this.value==value || (this.value != null && this.value.equals(value)))
            return;
        this.value = value;
    }

    public boolean isZipField() {
        return zipField;
    }

    public void setZipField(boolean zipField) {
        this.zipField = zipField;
    }

    public boolean isUploadName() {
        return uploadName;
    }

    public void setUploadName(boolean uploadName) {
        this.uploadName = uploadName;
    }

    public String getMode() {
        return mode;
    }

    public void setMode(String mode) {
        this.mode = mode;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public String getViewKey() {
        return viewKey;
    }

    public void setViewKey(String viewKey) {
        this.viewKey = viewKey;
    }

    public Map<String, Field> getCollectionValue() {
        return collectionValue;
    }

    public void setCollectionValue(Map<String, Field> collectionValue) {
        this.collectionValue = collectionValue;
    }

    public List<Select> getShowSelects() {
        return showSelects;
    }

    public void setShowSelects(List<Select> showSelects) {
        this.showSelects = showSelects;
    }

    public String getLastSelectValue() {
        return lastSelectValue;
    }

    public void setLastSelectValue(String lastSelectValue) {
        this.lastSelectValue = lastSelectValue;
    }

    public boolean isRequired()
    {
        return required;
    }

    public void setRequired(boolean required)
    {
        this.required = required;
    }
}
