package com.njcn.product.terminal.mysqlTerminal.pojo.param;

import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.common.pojo.dto.SimpleDTO;

import com.njcn.product.terminal.mysqlTerminal.pojo.constant.ValidMessage;
import com.njcn.product.terminal.mysqlTerminal.pojo.enums.LineFlagEnum;
import com.njcn.product.terminal.mysqlTerminal.pojo.enums.PowerFlagEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2022年02月23日 19:04
 */
@Data
@ApiModel
@NoArgsConstructor
public class DeviceInfoParam implements Serializable {

    /**
     * 统计类型
     */
    @ApiModelProperty(name = "statisticalType", value = "统计类型", required = true)
    private SimpleDTO statisticalType;

    @ApiModelProperty(name = "deptIndex", value = "部门索引", required = true)
    @NotBlank(message = "部门索引不可为空")
    private String deptIndex;

    @ApiModelProperty(name = "serverName", value = "服务名称")
    private String serverName;


    @ApiModelProperty(name = "scale", value = "电压等级")
    private List<SimpleDTO> scale;


    @ApiModelProperty(name = "manufacturer", value = "终端厂家")
    private List<SimpleDTO> manufacturer;


    @ApiModelProperty(name = "loadType", value = "干扰源类型")
    private List<SimpleDTO> loadType;

    /**
     * xy添加
     * 默认true
     * true     statFlag = 1
     * false    statFlag = 0 or 1
     */
    @ApiModelProperty(name = "statFlag", value = "人为干预是否参与统计")
    private Boolean statFlag;

    /**
     * 0-非网公司
     * 1-网公司
     * 2-全部数据
     */
    @ApiModelProperty("网公司标识")
    @Range(min = 0, max = 2, message = "网公司标识" + ValidMessage.PARAM_FORMAT_ERROR)
    private Integer monitorFlag;

    /**
     * 0-电网侧
     * 1-非电网侧
     */
    @ApiModelProperty("电网侧标识")
    @Range(min = 0, max = 2, message = "电网侧标识" + ValidMessage.PARAM_FORMAT_ERROR)
    private Integer powerFlag;

    /**
     * 0-极重要
     * 1-重要
     * 2-普通
     * 3-不重要
     */
    @ApiModelProperty("监测点等级")
    private String lineGrade;

    /**
     * 通讯状态（0：中断；1：正常）
     */
    @ApiModelProperty("通讯状态")
    @Range(min = 0, max = 2, message = "通讯状态" + ValidMessage.PARAM_FORMAT_ERROR)
    private Integer comFlagStatus;


    /**
     * 监测点运行状态（0：运行；1：检修；2：停运；3：调试；4：退运）
     */
    @ApiModelProperty("监测点运行状态")
    @Range(min = 0, max = 2, message = "监测点运行状态" + ValidMessage.PARAM_FORMAT_ERROR)
    private Integer lineRunFlag;

    /**
     * 默认全部监测点
     *
     * @param deptIndex  部门索引
     * @param serverName 服务名
     */
    public DeviceInfoParam(String deptIndex, String serverName) {
        this.deptIndex = deptIndex;
        this.serverName = serverName;
        monitorFlag = LineFlagEnum.LINE_MONITOR_ALL.getFlag();
        powerFlag = LineFlagEnum.LINE_POWER_ALL.getFlag();
    }


    /**
     * 默认全部监测点
     *
     * @param deptIndex  部门索引
     * @param serverName 服务名
     */
    public DeviceInfoParam(SimpleDTO statisticalType, String deptIndex, String serverName, List<SimpleDTO> scale, List<SimpleDTO> manufacturer, List<SimpleDTO> loadType) {
        this.statisticalType = statisticalType;
        this.deptIndex = deptIndex;
        this.serverName = serverName;
        this.scale = scale;
        this.manufacturer = manufacturer;
        this.loadType = loadType;
        monitorFlag = LineFlagEnum.LINE_MONITOR_ALL.getFlag();
        powerFlag = LineFlagEnum.LINE_POWER_ALL.getFlag();
    }

    /**
     * 自定义上报方式、电网侧方式的统计
     */
    public DeviceInfoParam(SimpleDTO statisticalType, String deptIndex, String serverName, List<SimpleDTO> scale, List<SimpleDTO> manufacturer, List<SimpleDTO> loadType, int monitorFlag, int powerFlag) {
        this.statisticalType = statisticalType;
        this.deptIndex = deptIndex;
        this.serverName = serverName;
        this.scale = scale;
        this.manufacturer = manufacturer;
        this.loadType = loadType;
        this.monitorFlag = monitorFlag;
        this.powerFlag = powerFlag;
    }

    @Data
    @EqualsAndHashCode(callSuper = true)
    public static class BusinessParam extends DeviceInfoParam {

        @ApiModelProperty("开始时间")
        @Pattern(regexp = PatternRegex.TIME_FORMAT, message = "时间格式错误")
        private String searchBeginTime;

        @ApiModelProperty("结束时间")
        @Pattern(regexp = PatternRegex.TIME_FORMAT, message = "时间格式错误")
        private String searchEndTime;

        @ApiModelProperty("时间范围标志 0.查询展示天 1.查询展示月")
        @Deprecated
        private Integer timeFlag;

        @ApiModelProperty("统计类型 1.年 2.季 3.月 4.周 5.天")
        private String reportFlag;

    }

    @Data
    @EqualsAndHashCode(callSuper = true)
    public static class CompareBusinessParam extends BusinessParam {

        @ApiModelProperty("比较开始时间")
        @Pattern(regexp = PatternRegex.TIME_FORMAT, message = "时间格式错误")
        private String periodBeginTime;

        @ApiModelProperty("比较结束时间")
        @Pattern(regexp = PatternRegex.TIME_FORMAT, message = "时间格式错误")
        private String periodEndTime;

    }

    @Data
    @EqualsAndHashCode(callSuper = true)
    public static class CompareLimitParam extends BusinessParam {

        @ApiModelProperty("查询条数")
        @NotNull(message = " 查询条数查询条数不能为空")
        private Integer limit;

    }

    @Data
    @EqualsAndHashCode(callSuper = true)
    public static class GridDiagram extends BusinessParam {

        @ApiModelProperty("查询总数监测点")
        private List<String> coutList;

        @ApiModelProperty("查询告警监测点")
        private List<String> alarmList;

        @ApiModelProperty("是否是冀北电网一张图树 0:否 1:是")
        private Integer type = 0;
    }

    public Boolean isUserLedger() {
        if (Objects.isNull(this.powerFlag) || !PowerFlagEnum.GRID_SIDE.getCode().equals(this.powerFlag)) {
            return true;
        }
        return false;
    }
}
