package com.pwt.netty.message2;

import lombok.Getter;
import lombok.Setter;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Objects;

@Getter
public class Alarm extends BaseData{


    /**
     * 告警代码
     */
    private final String code;

    private String id;

    public String getId() {
        return code;
    }

    /**
     * 告警描述
     */
    @Setter
    private String description;

    /**
     * 告警级别
     */
    @Setter
    private int level;


    /**
     *  1: 站控 2 机器人 3充电()枪 4 电池 5 车载控制器
     * 站控[首页告警信息]
     *
     */
    private final int sourceDeviceType;

    /**
     * 来源设备ID,如果是电池，则ID为电池仓ID, 如果是充电监控则为充电枪id
     */
    private final String sourceDeviceId;

    /**
     * 触发时间
     */
    @Getter
    private final LocalDateTime dateTime;

    @Setter
    private Boolean isDelete = false;

    public Alarm(String code, int sourceDeviceType, String sourceDeviceId) {
        this.code = code;
        this.sourceDeviceType = sourceDeviceType;
        this.sourceDeviceId = sourceDeviceId;
        dateTime = Instant.ofEpochMilli(getTimestamp()).atOffset(ZoneOffset.ofHours(8)).toLocalDateTime();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Alarm alarm = (Alarm) o;
        return sourceDeviceType == alarm.sourceDeviceType && code.equals(alarm.code) && sourceDeviceId.equals(alarm.sourceDeviceId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(code, sourceDeviceType, sourceDeviceId);
    }
}
