package com.limap.core.screen.vo;


import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;

@Data
@ApiModel(value = "AppEquipmentVo", description = "设备信息")
public class AppEquipmentVo {

    @ApiModelProperty("设备id")
    private Long id;

    @ApiModelProperty("用户id")
    private Long userId;

    @ApiModelProperty("物联网id")
    private String iotId;

    @ApiModelProperty("设备编码")
    private String serialNum;

    @ApiModelProperty("设备名称")
    private String deviceName;

    @ApiModelProperty("设备类型 1水质 2 测控一体")
    private String deviceType;

    private Date bindTime;
    private Date deadTime;

    private Long pondId;

    @ApiModelProperty("池塘名称")
    private String pondName;

    @ApiModelProperty("测控一体判断是否有溶氧")
    private Boolean oxygenUsed;

    @ApiModelProperty("溶氧")
    private Double dissolvedOxygen;

    @ApiModelProperty("水温")
    private Double temperature;

    @ApiModelProperty("饱和度")
    private Double saturability;

    @ApiModelProperty("ph")
    private Double  pH;

    @ApiModelProperty("盐度")
    private Double salinity;

    @ApiModelProperty("溶解氧报警下限")
    private Double oxyWarnLower;

    @ApiModelProperty("溶氧报警开关")
    private Boolean oxyWarnCallOpen;

    @ApiModelProperty("溶氧报警免打扰开关")
    private Boolean oxyWarnCallNoDis;

    @ApiModelProperty("温度报警下限")
    private Double tempWarnLower;

    @ApiModelProperty("温度报警上限")
    private Double tempWarnUpper;

    @ApiModelProperty("温度报警开关")
    private Boolean tempWarnCallOpen;

    @ApiModelProperty("温度报警免打扰开关")
    private Boolean tempWarnCallNoDis;

    @ApiModelProperty("输入额定电压 测控一体")
    private Double inputVoltage;

    @ApiModelProperty("告警码 测控一体")
    private String warnCode;

    @TableField(exist = false)
    private Integer online;

    @ApiModelProperty("deviceType 为2时，返回开关信息")
    private List<ControlSwitch> switches;

    // Setter 方法：保留两位小数
    public void setDissolvedOxygen(Double dissolvedOxygen) {
        this.dissolvedOxygen = roundToTwoDecimals(dissolvedOxygen);
    }

    public void setTemperature(Double temperature) {
        this.temperature = roundToTwoDecimals(temperature);
    }

    public void setSaturability(Double saturability) {
        this.saturability = roundToTwoDecimals(saturability);
    }

    public void setPH(Double pH) {
        this.pH = roundToTwoDecimals(pH);
    }

    public void setSalinity(Double salinity) {
        this.salinity = roundToTwoDecimals(salinity);
    }

    public void setOxyWarnLower(Double oxyWarnLower) {
        this.oxyWarnLower = roundToTwoDecimals(oxyWarnLower);
    }

    public void setTempWarnLower(Double tempWarnLower) {
        this.tempWarnLower = roundToTwoDecimals(tempWarnLower);
    }

    public void setTempWarnUpper(Double tempWarnUpper) {
        this.tempWarnUpper = roundToTwoDecimals(tempWarnUpper);
    }

    public void setInputVoltage(Double inputVoltage) {
        this.inputVoltage = roundToTwoDecimals(inputVoltage);
    }

    // 工具方法：保留两位小数
    private Double roundToTwoDecimals(Double value) {
        if (value == null) {
            return null;
        }
        return BigDecimal.valueOf(value)
                .setScale(2, RoundingMode.HALF_UP)
                .doubleValue();
    }
}
