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

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import net.opentsdb.client.api.BaseRequest;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: qh
 * @create: 2020-05-06 15:52
 **/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PutRequestExt extends BaseRequest {

    private Boolean summary = false;
    private Boolean details = false;
    private Boolean sync = false;
    private Long syncTimeout = 0L;
    private List<PutExt> dataPoints;

    public PutRequestExt addDataPoints(PutExt query) {
        if (getDataPoints() == null) {
            setDataPoints(new ArrayList<>());
        }
        getDataPoints().add(query);
        return this;
    }

    public Map<String, String> getParameters() {
        Map<String, String> parameters = new LinkedHashMap();
        if (this.summary != null && this.summary) {
            parameters.put("summary", "");
        }

        if (this.details != null && this.details) {
            parameters.put("details", "");
        }

        if (this.sync != null && this.sync) {
            parameters.put("sync", "");
        }

        if (this.sync != null && this.sync && this.syncTimeout != null && this.syncTimeout > 0L) {
            parameters.put("sync_timeout", this.syncTimeout.toString());
        }

        return parameters;
    }
}
