package com.purui.prims.common.pojo;


import com.purui.prims.common.pojo.enums.FilterOperatorEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Filter {

    @ApiModelProperty(value = "关系")
    private Relation relation = Relation.FILTER;

    @ApiModelProperty(value = "id")
    private Long id;

    @ApiModelProperty(value = "业务名称")
    private String bizName;

    @ApiModelProperty(value = "名称")
    private String name;

    @ApiModelProperty(value = "操作符")
    private FilterOperatorEnum operator;

    @ApiModelProperty(value = "值")
    private Object value;

    @ApiModelProperty(value = "子条件")
    private List<Filter> children;

    public Filter(String bizName, FilterOperatorEnum operator, Object value) {
        this.bizName = bizName;
        this.operator = operator;
        this.value = value;
    }

    public Filter(Relation relation, String bizName, FilterOperatorEnum operator, Object value) {
        this.relation = relation;
        this.bizName = bizName;
        this.operator = operator;
        this.value = value;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("{");
        sb.append("\"relation\":")
                .append(relation);
        sb.append(",\"bizName\":\"")
                .append(bizName).append('\"');
        sb.append(",\"name\":\"")
                .append(name).append('\"');
        sb.append(",\"operator\":")
                .append(operator);
        sb.append(",\"value\":")
                .append(value);
        sb.append(",\"children\":")
                .append(children);
        sb.append('}');
        return sb.toString();
    }

    public enum Relation {
        FILTER, OR, AND
    }
}