package com.njcn.gather.device.pojo.param;

import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.monitor.pojo.param.PqMonitorParam;
import com.njcn.gather.pojo.constant.DetectionValidMessage;
import com.njcn.web.pojo.annotation.DateTimeStrValid;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Range;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;

/**
 * @author caozehui
 * @date 2024/11/06
 */
@Data
public class PqDevParam {

    @ApiModelProperty(value = "名称", required = true)
    @NotBlank(message = DetectionValidMessage.NAME_NOT_BLANK)
    private String name;

    @ApiModelProperty(value = "设备模式，字典表（数字、模拟、比对）", required = true)
    @NotBlank(message = DetectionValidMessage.PATTERN_NOT_BLANK)
    @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.PATTERN_FORMAT_ERROR)
    private String pattern;

    @ApiModelProperty(value = "设备类型", required = true)
    @NotBlank(message = DetectionValidMessage.DEV_TYPE_NOT_BLANK)
    @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.DEV_TYPE_FORMAT_ERROR)
    private String devType;

    @ApiModelProperty(value = "设备厂家，字典表", required = true)
    private String manufacturer;

    @ApiModelProperty(value = "出厂日期", required = true)
    private String createDate;

    @ApiModelProperty(value = "装置编号", required = true)
    @NotBlank(message = DetectionValidMessage.FACTORYNO_NOT_BLANK)
    @Pattern(regexp = PatternRegex.DEV_CREATE_ID_REGEX, message = DetectionValidMessage.DEV_CREATE_ID_FORMAT_ERROR)
    private String createId;

    @ApiModelProperty(value = "固件版本", required = true)
    private String hardwareVersion;

    @ApiModelProperty(value = "软件版本", required = true)
    private String softwareVersion;

    @ApiModelProperty(value = "通讯协议", required = true)
    @NotBlank(message = DetectionValidMessage.PROTOCOL_NOT_BLANK)
    @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.PROTOCOL_FORMAT_ERROR)
    private String protocol;

    @ApiModelProperty(value = "IP地址", required = true)
    @NotBlank(message = DetectionValidMessage.IP_NOT_BLANK)
    @Pattern(regexp = PatternRegex.IP_REGEX, message = DetectionValidMessage.IP_FORMAT_ERROR)
    private String ip;

    @ApiModelProperty(value = "端口号", required = true)
    @NotNull(message = DetectionValidMessage.PORT_NOT_NULL)
    @Range(min = 1, max = 65535, message = DetectionValidMessage.PORT_RANGE_ERROR)
    private Integer port;

    @ApiModelProperty(value = "装置是否为加密版本", required = true)
    @NotNull(message = DetectionValidMessage.ENCRYPTION_NOT_NULL)
    @Min(value = 0, message = DetectionValidMessage.ENCRYPTION_FLAG_FORMAT_ERROR)
    @Max(value = 1, message = DetectionValidMessage.ENCRYPTION_FLAG_FORMAT_ERROR)
    private Integer encryptionFlag;

    @ApiModelProperty("装置识别码（3ds加密）")
    private String series;

    @ApiModelProperty("装置秘钥（3ds加密）")
    private String devKey;

    @ApiModelProperty("样品编号")
    private String sampleId;

    @ApiModelProperty(value = "送样日期")
    @DateTimeStrValid(message = DetectionValidMessage.ARRIVE_DATE_FORMAT_ERROR)
    private String arrivedDate;

    @ApiModelProperty("所属地市名称")
    private String cityName;

    @ApiModelProperty("所属供电公司名称")
    private String gdName;

    @ApiModelProperty("所属电站名称")
    private String subName;

    @ApiModelProperty("报告路径")
    private String reportPath;

//    @ApiModelProperty("设备关键信息二维码")
//    private String qrCode;

//    @ApiModelProperty(value = "检测次数,默认为0", required = true)
//    @NotNull(message = DetectionValidMessage.RECHECK_NUM_NOT_NULL)
//    @Min(value = 0, message = DetectionValidMessage.RECHECK_NUM_FORMAT_ERROR)
//    private Integer reCheckNum;

    @ApiModelProperty("是否支持系数校准")
    private Integer factorFlag;

    @ApiModelProperty("监测点台账列表")
    @Valid
    private List<PqMonitorParam> monitorList;

    @ApiModelProperty("icdId")
    private String icdId;

    @ApiModelProperty("预投计划")
    private String preinvestmentPlan;

    @ApiModelProperty("委托方")
    private String delegate;

    @ApiModelProperty("被检通道")
    private String inspectChannel;

    @ApiModelProperty("投运日期")
    @DateTimeStrValid(message = DetectionValidMessage.OPERATION_DATE_FORMAT_ERROR)
    private String operationDate;

    @ApiModelProperty("定验日期")
    @DateTimeStrValid(message = DetectionValidMessage.INSPECT_DATE_FORMAT_ERROR)
    private String inspectDate;

    @ApiModelProperty("是否为导入设备")
    private Integer importFlag;

    @ApiModelProperty("设备图片")
    private List<MultipartFile> images;

    /**
     * 更新操作实体
     */
    @Data
    @EqualsAndHashCode(callSuper = true)
    public static class UpdateParam extends PqDevParam {

        @ApiModelProperty(value = "id", required = true)
        @NotBlank(message = DetectionValidMessage.ID_NOT_BLANK)
        @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ID_FORMAT_ERROR)
        private String id;

        @ApiModelProperty("deleteImageNames")
        private List<String> deleteImageNames;
    }

    /**
     * 分页查询实体
     */
    @Data
    @EqualsAndHashCode(callSuper = true)
    public static class QueryParam extends BaseParam {
        @ApiModelProperty("名称")
        private String name;

        @ApiModelProperty(value = "设备模式，字典表（数字、模拟、比对）")
        private String pattern;

        @ApiModelProperty("设备厂家")
        private String manufacturer;

        @ApiModelProperty("检测计划ID")
        private List<String> planIdList;

        @ApiModelProperty("检测状态列表")
        private List<
                @Min(value = 0, message = DetectionValidMessage.CHECK_STATE_FORMAT_ERROR)
                @Max(value = 3, message = DetectionValidMessage.CHECK_STATE_FORMAT_ERROR) Integer> checkStateList;

        @ApiModelProperty("检测结果")
        @Min(value = 0, message = DetectionValidMessage.CHECK_RESULT_FORMAT_ERROR)
        @Max(value = 2, message = DetectionValidMessage.CHECK_RESULT_FORMAT_ERROR)
        private Integer checkResult;

        @ApiModelProperty("报告状态")
        @Min(value = 0, message = DetectionValidMessage.REPORT_STATE_FORMAT_ERROR)
        @Max(value = 2, message = DetectionValidMessage.REPORT_STATE_FORMAT_ERROR)
        private Integer reportState;

        @ApiModelProperty("所属地市名称")
        private String cityName;

        @ApiModelProperty("所属供电公司名称")
        private String gdName;

        @ApiModelProperty("所属电站名称")
        private String subName;

        @ApiModelProperty("地市")
        private String region;

        @ApiModelProperty("是否分配")
        private Integer assign;
        @ApiModelProperty("关键词")
        private String keywords;
        @ApiModelProperty("主计划ID")
        private String planId;
        @ApiModelProperty("是否分配子计划")
        private Integer assignSub;
    }

    @Data
    public static class DeleteParam {
        @ApiModelProperty(value = "ids")
        private List<@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ID_FORMAT_ERROR) String> ids;

        @ApiModelProperty(value = "设备模式，字典表（数字、模拟、比对）", required = true)
        @NotBlank(message = DetectionValidMessage.PATTERN_NOT_BLANK)
        @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.PATTERN_FORMAT_ERROR)
        private String pattern;
    }

    @Data
    public static class BindPlanParam {
        @ApiModelProperty("检测计划ID")
        @NotBlank(message = DetectionValidMessage.PLAN_ID_NOT_BLANK)
        @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.PLAN_ID_FORMAT_ERROR)
        private String planId;

        @ApiModelProperty("被检设备ID列表")
        @NotNull(message = DetectionValidMessage.PQ_DEV_IDS_NOT_NULL)
        private List<String> devIds;

        @ApiModelProperty("0-解绑、1-绑定")
        private Integer bindFlag;
    }
}
