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

import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.plan.pojo.po.AdPlanTestConfig;
import com.njcn.gather.pojo.constant.DetectionValidMessage;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

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

/**
 * @author caozehui
 * @data 2024-12-09
 */
@Data
public class AdPlanParam {

    @ApiModelProperty(value = "名称", required = true)
    @NotBlank(message = DetectionValidMessage.NAME_NOT_BLANK)
    @Pattern(regexp = PatternRegex.PLAN_NAME_REGEX, message = DetectionValidMessage.NAME_FORMAT_ERROR)
    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 = "检测源ID列表", required = true)
    private List<@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.SOURCE_ID_FORMAT_ERROR) String> sourceIds;

    @ApiModelProperty(value = "数据源ID列表", required = true)
    @NotEmpty(message = DetectionValidMessage.DATASOURCE_ID_NOT_EMPTY)
    private List<String> datasourceIds;

    @ApiModelProperty(value = "检测脚本ID", required = true)
    private String scriptId;

    @ApiModelProperty(value = "误差体系ID", required = true)
    @NotBlank(message = DetectionValidMessage.ERROR_SYS_ID_NOT_BLANK)
    @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ERROR_SYS_ID_FORMAT_ERROR)
    private String errorSysId;

    @ApiModelProperty(value = "守时检测")
    @NotNull(message = DetectionValidMessage.TIME_CHECK_NOT_NULL)
    @Min(value = 0, message = DetectionValidMessage.TIME_CHECK_FORMAT_ERROR)
    @Max(value = 1, message = DetectionValidMessage.TIME_CHECK_FORMAT_ERROR)
    private Integer timeCheck;

    @ApiModelProperty("被检设备ID列表")
    private List<String> devIds;

    @ApiModelProperty(value = "是否关联报告")
    @NotNull(message = DetectionValidMessage.ASSOCIATE_REPORT_NOT_NULL)
    private Integer associateReport;

    @ApiModelProperty(value = "报告模板名称")
    private String reportTemplateName;

    @ApiModelProperty(value = "数据处理原则")
    @NotBlank(message = DetectionValidMessage.DATA_RULE_NOT_BLANK)
    private String dataRule;

    @ApiModelProperty(value = "父计划ID")
    private String fatherPlanId;

    @ApiModelProperty(value = "标准设备ID列表")
    private List<String> standardDevIds;

    @ApiModelProperty(value = "测试项ID列表")
    private List<@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.SOURCE_ID_FORMAT_ERROR) String> testItems;

    @ApiModelProperty(value = "检测配置")
    private AdPlanTestConfig testConfig;

    @ApiModelProperty(value = "检测负责人")
    private String leader;

    @ApiModelProperty(value = "检测成员")
    private List<String> memberIds;

    /**
     * 分页查询实体
     */
    @Data
    @EqualsAndHashCode(callSuper = true)
    public static class QueryParam extends BaseParam {
        @ApiModelProperty("名称")
        @Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DetectionValidMessage.NAME_FORMAT_ERROR)
        private String name;

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

        @ApiModelProperty(value = "检测状态")
        @Min(value = 0, message = DetectionValidMessage.TEST_STATE_FORMAT_ERROR)
        @Max(value = 2, message = DetectionValidMessage.TEST_STATE_FORMAT_ERROR)
        private Integer testState;

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

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

    @Data
    @EqualsAndHashCode(callSuper = true)
    public static class UpdateParam extends AdPlanParam {
        @ApiModelProperty(value = "id", required = true)
        @NotBlank(message = DetectionValidMessage.ID_NOT_BLANK)
        @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DetectionValidMessage.ID_FORMAT_ERROR)
        private String id;
    }

    @Data
    public static class CheckParam {
        // 0:不合格项复检 1:全部复检
        private Integer reCheckType;
        private String planId;
        private List<String> devIds;
        private String patternId;
        private String scriptType;
    }

    @Data
    public static class StatisticsParam {
        @ApiModelProperty(value = "检测计划ID", required = true)
        @NotBlank(message = DetectionValidMessage.PLAN_ID_NOT_BLANK)
        private String planId;

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

        @ApiModelProperty("设备类型")
        private String devType;
    }
}
