package com.huatek.busi.dto.curve;

import java.io.Serializable;
import java.time.LocalDate;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 二级告警界面曲线图请求参数Dto
 * 
 * @author anker_cheng
 * @date 2019/09/03
 */
@Data
@ApiModel(value = "CurveSensorRequestDto", description = "二级告警界面曲线图请求参数Dto")
public class CurveSensorRequestDto implements Serializable {
    private static final long serialVersionUID = 267069682307814532L;

    @ApiModelProperty(hidden = true)
    private final int DEFAULT_DAYS = 7;

    @ApiModelProperty(name = "eqType", value = "告警大类", required = true)
    private String eqType;

    @ApiModelProperty(name = "gzType", value = "告警小类", required = true)
    private String gzType;

    @ApiModelProperty(name = "sensorCode", value = "传感器编码", required = true)
    private String sensorCode;

    @ApiModelProperty(name = "mainTreeId", value = "站点设备树ID", required = true)
    private String mainTreeId;

    @ApiModelProperty(name = "startDate", value = "开始日期")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate startDate;

    @ApiModelProperty(name = "endDate", value = "结束日期")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate endDate;

    public CurveSensorRequestDto check() {
        if (this.getStartDate() == null && this.getEndDate() == null) {
            this.setEndDate(LocalDate.now());
            this.setStartDate(this.getEndDate().minusDays(DEFAULT_DAYS));
        } else if (this.getStartDate() == null) {
            this.setStartDate(this.getEndDate().minusDays(DEFAULT_DAYS));
        } else if (this.getEndDate() == null) {
            this.setEndDate(this.getStartDate().plusDays(DEFAULT_DAYS));
        }
        if(StringUtils.isEmpty(this.sensorCode)) {
            this.sensorCode = this.mainTreeId;
        }
        return this;
    }
}
