package   cn.wise.sc.energy.power.plant.business.opentsdb.bean;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import net.opentsdb.client.bean.Aggregator;
import net.opentsdb.client.bean.BaseBean;
import net.opentsdb.client.bean.Filter;
import net.opentsdb.client.bean.RateOptions;

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

/**
 * @author neo.shu
 * @since 2020/4/28 19:35
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class QueryExt extends BaseBean {

    private Aggregator aggregator;

    private String metric;
    private Boolean rate;
    private RateOptions rateOptions;
    private String downsample;
    private Map<String, String> tags;
    private List<Filter> filters;
    private Boolean explicitTags;
    private List<Float> percentiles;
    private String rollupUsage;

    public QueryExt addFilter(Filter filter) {
        if (getFilters() == null) {
            setFilters(new ArrayList<>());
        }
        getFilters().add(filter);
        return this;
    }

    public QueryExt putTag(String key, String value) {
        if (getTags() == null) {
            setTags(new HashMap<>());
        }
        getTags().putIfAbsent(key, value);
        return this;
    }
}
