/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.coldchain.modular.monitortargetregion.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import vip.xiaonuo.coldchain.core.alarm.bean.NotificationChannel;
import vip.xiaonuo.coldchain.core.alarm.bean.SensorAlarmUser;
import vip.xiaonuo.coldchain.core.handler.NotificationChannelListTypeHandler;
import vip.xiaonuo.coldchain.core.handler.SensorAlarmUserTypeHandler;
import vip.xiaonuo.common.pojo.OrgEntity;

import java.util.List;

/**
 * 区域管理实体
 *
 * @author 黄渊昊
 * @date 2024/11/13 16:57
 **/
@Getter
@Setter
@TableName(value = "monitor_target_region", autoResultMap = true)
public class MonitorTargetRegion extends OrgEntity {
    /**
     * 区域唯一标识符，UUID
     */
    @TableId
    @Schema(description = "区域唯一标识符，UUID")
    private String id;

    /**
     * 区域名称
     */
    @Schema(description = "区域名称")
    private String name;

    /**
     * 上级区域ID
     */
    @Schema(description = "上级区域ID")
    private String parentId;

    /**
     * 监控监控对象
     */
    @Schema(description = "监控监控对象")
    private String monitorTargetId;

    /**
     * 传感器编号
     */
    @Schema(description = "传感器编号")
    private String sensorCode;

    /**
     * 传感器类型
     */
    @Schema(description = "传感器类型")
    private String sensorType;

    /**
     * 传感器路数
     */
    @Schema(description = "传感器路数")
    private Integer sensorRoute;

    /**
     * 监控设备型号
     */
    @Schema(description = "监控设备型号")
    private String modelName;

    /**
     * 监控设备编号
     */
    @Schema(description = "监控设备编号")
    private String monitorDeviceId;

    /**
     * 冷链编号
     */
    @Schema(description = "冷链编号")
    private String deviceCode;


    /**
     * 设备下线预警
     */
    @Schema(description = "设备下线预警")
    private Boolean deviceOfflineAlarm;

    /**
     * 温度报警上限 temperature humidity co2
     */
    @Schema(description = "温度报警上限")
//    @JsonSerialize(using = FloatNullToDashSerializer.class)
//    @JsonFormat(shape = JsonFormat.Shape.NUMBER_FLOAT, pattern = "#.00")
    private Float temperatureUp;
    /**
     * 温度报警下限
     */
    @Schema(description = "温度报警下限")
//    @JsonSerialize(using = FloatNullToDashSerializer.class)
//    @JsonFormat(shape = JsonFormat.Shape.NUMBER_FLOAT, pattern = "#.00")
    private Float temperatureDown;

    /**
     * 湿度报警上限 temperature humidity co2
     */

    @Schema(description = "湿度报警上限")
//    @JsonSerialize(using = FloatNullToDashSerializer.class)
//    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "#.00")
    private Float humidityUp;
    /**
     * 湿度报警下限
     */
    @Schema(description = "湿度报警下限")
//    @JsonSerialize(using = FloatNullToDashSerializer.class)
//    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "#.00")
    private Float humidityDown;

    /**
     * 二氧化碳报警上限 temperature humidity co2
     */
    @Schema(description = "二氧化碳报警上限")
//    @JsonSerialize(using = FloatNullToDashSerializer.class)
//    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "#.00")
    private Float co2Up;

    /**
     * 二氧化碳报警下限
     */
    @Schema(description = "二氧化碳报警下限")
//    @JsonSerialize(using = FloatNullToDashSerializer.class)
//    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "#.00")
    private Float co2Down;

    /**
     * 低电量报警下限
     */
    @Schema(description = "低电量报警下限")
    private Float batteryDown;

    /**
     * 监控对象名称
     */
    @TableField(exist = false)
    @Schema(description = "监控对象名称")
    private String targetName;

    /**
     * 监控设备名称
     */
    @TableField(exist = false)
    @Schema(description = "监控设备名称")
    private String deviceName;

    /**
     * 告警接收人，存储告警通知的接收用户信息
     */
    @Schema(description = "告警接收人，存储告警通知的接收用户信息")
    @TableField(value = "alarm_users", typeHandler = SensorAlarmUserTypeHandler.class)
//    @JsonIgnore
    private List<SensorAlarmUser> alarmUsers = Lists.newArrayList();

    /**
     * 用户的通知渠道设置，支持选择接收告警的多个渠道，如短信、邮件、APP通知等
     */
    @Schema(description = "用户的通知渠道设置，支持选择接收告警的多个渠道，如短信、邮件、APP通知等")
    @TableField(value = "notification_channel", typeHandler = NotificationChannelListTypeHandler.class)
    @JsonIgnore
    private List<NotificationChannel> notificationChannel = List.of(NotificationChannel.WECHAT);

    @Schema(description = "勿扰开始时间")
    private String ignoreStartTime;

    @Schema(description = "勿扰结束时间")
    private String ignoreEndTime;

    /**
     * 房间名
     */
    @Schema(description = "房间名")
    @TableField(exist = false)
    private String roomName;

    public void setTemperatureUp(Float temperatureUp) {
        this.temperatureUp = temperatureUp;
    }

    public void setTemperatureDown(Float temperatureDown) {
        this.temperatureDown = temperatureDown;
    }

    public void setHumidityUp(Float humidityUp) {
        this.humidityUp = humidityUp;
    }

    public void setHumidityDown(Float humidityDown) {
        this.humidityDown = humidityDown;
    }

    public void setCo2Up(Float co2Up) {
        this.co2Up = co2Up;
    }

    public void setCo2Down(Float co2Down) {
        this.co2Down = co2Down;
    }


    public String getDeviceCodeAndSensorRoute() {
        return this.deviceCode + ":" + this.sensorRoute;
    }

}
