package cn.stylefeng.team.meta.db.pojo.query;

import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.team.meta.db.util.QueryConditionUtil;

public class FilterItem {

    @ChineseDescription("字段名")
    private String field;

    @ChineseDescription("操作符号")
    private String operator;

    @ChineseDescription("值")
    private Object value;

    @ChineseDescription("逻辑符号")
    private String logic;

    @ChineseDescription("子组")
    private Group group;

    @ChineseDescription("子组的逻辑符号")
    private String groupLogic;

    public FilterItem() {
    }

    public FilterItem(String field, String operator, Object value, String logic, Group group, String groupLogic) {
        QueryConditionUtil.validateField(field);
        QueryConditionUtil.validateOperator(operator);
        QueryConditionUtil.validateLogic(logic);
        this.field = field;
        this.operator = operator.toUpperCase();
        this.value = value;
        this.logic = logic.toUpperCase();
        this.group = group;
        this.groupLogic = groupLogic;
    }

    public String getField() {
        return field;
    }

    public void setField(String field) {
        QueryConditionUtil.validateField(field);
        this.field = field;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        QueryConditionUtil.validateOperator(operator);
        this.operator = operator.toUpperCase();
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        if (value == null) {
            throw new IllegalArgumentException("Value cannot be null");
        }
        this.value = value;
    }

    public String getLogic() {
        return logic;
    }

    public void setLogic(String logic) {
        QueryConditionUtil.validateLogic(logic);
        this.logic = logic.toUpperCase();
    }

    public Group getGroup() {
        return group;
    }

    public void setGroup(Group group) {
        this.group = group;
    }

    public String getGroupLogic() {
        return groupLogic;
    }

    public void setGroupLogic(String groupLogic) {
        if (groupLogic != null) {
            QueryConditionUtil.validateLogic(groupLogic);
            this.groupLogic = groupLogic.toUpperCase();
        }
    }
}
