package com.galaxis.manatee.entity.chuanyun;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * 氚云批量查询过滤条件,氚云技术人员建议查询全部数据，自己进行筛选
 * @author zcj
 * @version 0.1
 * @date 2020/2/5 10:01 下午
 */
@Getter
@Setter
public class Filter {
    /**
     *
     * @param fromRowNumber 从第几行开始
     * @param toRowNumber   到第几行
     * @param requireCount  是否需要总数
     * @return  Filter对象
     */
    public static Filter instance(Integer fromRowNumber,Integer toRowNumber,Boolean requireCount){
        return new Filter(fromRowNumber,toRowNumber,requireCount,new String[0],new String[0],"And",new String[0]);
    }
    /**
     * 分页查询，从第几条开始
     */
    @JsonProperty(value = "FromRowNum")
    private Integer fromRowNumber;
    /**
     * 分页查询，第几条结束
     */
    @JsonProperty(value = "ToRowNum")
    private Integer toRowNumber;
    /**
     * 查询的总行数
     */
    @JsonProperty(value = "RequireCount")
    private Boolean requireCount;
    /**
     * 返回的字段，不填返回所有
     */
    @JsonProperty(value = "ReturnItems")
    private String[] returnItem;
    /**
     * 排序字段，目前不支持使用，默认置空
     */
    @JsonProperty(value = "SortByCollection")
    private String[] sortByCollection;
    /**
     * 查询条件
     */
    @JsonProperty(value = "Matcher")
    private Matcher matcher;

    private Filter(Integer fromRowNumber, Integer toRowNumber, Boolean requireCount, String[] returnItem, String[] sortByCollection, String type,String[] matchers) {
        this.fromRowNumber = fromRowNumber;
        this.toRowNumber = toRowNumber;
        this.requireCount = requireCount;
        this.returnItem = returnItem;
        this.sortByCollection = sortByCollection;
        this.matcher = new Matcher(type,matchers);
    }

    @Getter
    @Setter
    static class Matcher{
        /**
         * 判断符号：与或非
         */
        @JsonProperty(value = "Type")
        private String type;

        /**
         * 判断条件
         */
        @JsonProperty(value = "Matchers")
        private String[] matchers;

        public Matcher(String type, String[] matchers) {
            this.type = type;
            this.matchers = matchers;
        }
    }
}
