package com.njcn.gather.systemmonitor.disk.pojo.param;

import com.njcn.gather.systemmonitor.disk.constant.DiskMonitorValidMessage;
import com.njcn.gather.systemmonitor.disk.pojo.dto.DiskMonitorNotifyHttpItem;
import com.njcn.gather.systemmonitor.disk.pojo.dto.DiskMonitorNotifyPathItem;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * 磁盘监控接口参数。
 */
public class DiskMonitorParam {

    @Data
    public static class PolicySaveParam {

        @ApiModelProperty("全局策略")
        @NotNull(message = DiskMonitorValidMessage.POLICY_NOT_NULL)
        @Valid
        private PolicyParam policy;

        @ApiModelProperty("盘符配置")
        @NotNull(message = DiskMonitorValidMessage.TARGETS_NOT_NULL)
        @Valid
        private List<TargetParam> targets = new ArrayList<>();
    }

    @Data
    public static class PolicyParam {

        @ApiModelProperty("策略ID")
        private Long id;

        @ApiModelProperty("策略名称")
        @NotBlank(message = DiskMonitorValidMessage.POLICY_NAME_NOT_BLANK)
        private String policyName;

        @ApiModelProperty("是否启用监控")
        private Boolean monitorEnabled;

        @ApiModelProperty("应用启动后立即执行一次")
        private Boolean runOnAppStart;

        @ApiModelProperty("每日统一执行时间")
        @NotBlank(message = DiskMonitorValidMessage.DAILY_RUN_TIME_NOT_BLANK)
        private String dailyRunTime;

        @ApiModelProperty("预警通知模式")
        private String warningNotifyMode;

        @ApiModelProperty("告警通知模式")
        private String alarmNotifyMode;

        @ApiModelProperty("备注")
        private String remark;
    }

    @Data
    public static class TargetParam {

        @ApiModelProperty("盘符配置ID")
        private Long id;

        @ApiModelProperty("盘符")
        @NotBlank(message = DiskMonitorValidMessage.DRIVE_LETTER_NOT_BLANK)
        private String driveLetter;

        @ApiModelProperty("是否监控")
        private Boolean monitorEnabled;

        @ApiModelProperty("预警使用率")
        @NotNull(message = DiskMonitorValidMessage.WARNING_USAGE_PERCENT_NOT_NULL)
        @Min(value = 1, message = DiskMonitorValidMessage.USAGE_PERCENT_FORMAT_ERROR)
        @Max(value = 100, message = DiskMonitorValidMessage.USAGE_PERCENT_FORMAT_ERROR)
        private Integer warningUsagePercent;

        @ApiModelProperty("告警使用率")
        @NotNull(message = DiskMonitorValidMessage.ALARM_USAGE_PERCENT_NOT_NULL)
        @Min(value = 1, message = DiskMonitorValidMessage.USAGE_PERCENT_FORMAT_ERROR)
        @Max(value = 100, message = DiskMonitorValidMessage.USAGE_PERCENT_FORMAT_ERROR)
        private Integer alarmUsagePercent;

        @ApiModelProperty("是否启用路径通知")
        private Boolean notifyPathEnabled;

        @ApiModelProperty("路径通知列表")
        @Valid
        private List<DiskMonitorNotifyPathItem> notifyPathList = new ArrayList<>();

        @ApiModelProperty("是否启用HTTP通知")
        private Boolean notifyHttpEnabled;

        @ApiModelProperty("HTTP通知列表")
        @Valid
        private List<DiskMonitorNotifyHttpItem> notifyHttpList = new ArrayList<>();

        @ApiModelProperty("备注")
        private String remark;
    }

    @Data
    public static class JobRunParam {

        @ApiModelProperty("任务来源")
        @NotBlank(message = DiskMonitorValidMessage.JOB_SOURCE_NOT_BLANK)
        private String jobSource;
    }

    @Data
    @EqualsAndHashCode(callSuper = true)
    public static class JobListParam extends BaseParam {
    }

    @Data
    public static class NotifyTestParam {

        @ApiModelProperty("盘符")
        @NotBlank(message = DiskMonitorValidMessage.DRIVE_LETTER_NOT_BLANK)
        private String driveLetter;
    }
}
