package com.multictrl.modules.business.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.multictrl.common.validator.group.AddGroup;
import com.multictrl.common.validator.group.UpdateGroup;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;


/**
 * 天气阻飞
 *
 * @author Sdy
 * @since 1.0.0 2026-06-15
 */
@Data
@Schema(name = "天气阻飞")
public class WeatherNoflyDTO implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    @Null(message = "标识必须为空", groups = AddGroup.class)
    @NotNull(message = "标识不能为空", groups = UpdateGroup.class)
    @Schema(description = "标识")
    private Long id;

    @NotNull(message = "机库SN不能为空", groups = {AddGroup.class, UpdateGroup.class})
    @Schema(description = "机库sn")
    private String dockSn;

    @NotNull(message = "是否开启阻飞不能为空", groups = {AddGroup.class, UpdateGroup.class})
    @Schema(description = "是否开启阻飞（开启后使用机库上报数据）")
    private Boolean isOpen;

    @Schema(description = "风速m/s")
    private Double windSpeed;

    @Schema(description = "雨（0关闭 1小雨 2中雨 3大雨）")
    private Integer rainfall;

    @JsonIgnore
    @Schema(hidden = true)
    @AssertTrue(message = "参数为空或错误", groups = {AddGroup.class, UpdateGroup.class})
    public boolean isIsOpenValid() {
        if (isOpen) {
            return windSpeed != null && rainfall != null && (rainfall == 0 || rainfall == 1);
        }
        return true;
    }

    @NotNull(message = "是否全部阻飞不能为空", groups = {AddGroup.class, UpdateGroup.class})
    @Schema(description = "是否全部阻飞（开启后全部阻飞不开启只阻飞计划库）")
    private Boolean isAllPrevent;

    @NotNull(message = "是否开启天气阻飞不能为空", groups = {AddGroup.class, UpdateGroup.class})
    @Schema(description = "是否开启天气阻飞（开启后在机库数据上增加天气预报数据）")
    private Boolean isOpenWeather;

    @Schema(description = "风速m/s（天气预报）")
    private Double windSpeedWeather;

    @Schema(description = "雨（天气预报 0关闭 1小雨 2中雨 3大雨）")
    private Integer rainfallWeather;

    @Schema(description = "雪（天气预报 0关闭 1小雪 2中雪 3大雪）")
    private Integer snowWeather;

    @Schema(description = "雾（天气预报 0关闭 1轻雾 2中雾 3大雾）")
    private Integer fogWeather;

    @Schema(description = "霾（天气预报 0关闭 1轻度霾 2中度霾 3重度霾）")
    private Integer hazeWeather;

    @Schema(description = "冰雹阻飞")
    private Boolean isHailWeather;

    @Schema(description = "沙尘暴阻飞")
    private Boolean isSandstormWeather;

    @Schema(description = "龙卷风阻飞")
    private Boolean isTornadoWeather;

    @Schema(description = "温度上限（摄氏度）")
    private Double temperatureMax;

    @Schema(description = "温度下限（摄氏度）")
    private Double temperatureMin;

    @JsonIgnore
    @Schema(hidden = true)
    @AssertTrue(message = "天气参数为空或错误", groups = {AddGroup.class, UpdateGroup.class})
    public boolean isIsOpenWeatherValid() {
        if (isOpenWeather) {
            return windSpeedWeather != null
                    && (rainfallWeather != null && rainfallWeather >= 0 && rainfallWeather <= 3)
                    && (snowWeather != null && snowWeather >= 0 && snowWeather <= 3)
                    && (fogWeather != null && fogWeather >= 0 && fogWeather <= 3)
                    && (hazeWeather != null && hazeWeather >= 0 && hazeWeather <= 3)
                    && isHailWeather != null
                    && isSandstormWeather != null
                    && isTornadoWeather != null
                    && temperatureMax != null
                    && temperatureMin != null;
        }
        return true;
    }
}
