package com.qaup.collision.websocket.message;

import lombok.Data;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.time.LocalDateTime;
import com.qaup.collision.pathconflict.model.entity.ConflictAlertLog;

/**
 * 路径冲突告警WebSocket消息
 * 用于向前端控制台发送路径冲突告警信息
 * 
 * @author AI Assistant
 * @version 1.0
 * @since 2025-01-17
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PathConflictAlertMessage {
    
    /**
     * 消息类型
     */
    @Builder.Default
    private String messageType = "PATH_CONFLICT_ALERT";
    
    /**
     * 冲突ID
     */
    private Long conflictId;
    
    /**
     * 告警类型：WARNING, ALERT, EMERGENCY
     */
    private ConflictAlertLog.AlertType alertType;
    
    /**
     * 告警级别：WARNING, CRITICAL, EMERGENCY
     */
    private ConflictAlertLog.AlertLevel alertLevel;
    
    /**
     * 告警消息
     */
    private String message;
    
    /**
     * 冲突对象1
     */
    private ConflictObject object1;
    
    /**
     * 冲突对象2
     */
    private ConflictObject object2;
    
    /**
     * 冲突位置
     */
    private Position position;
    
    /**
     * 对象1距离冲突点距离 (米)
     */
    private Double object1Distance;

    /**
     * 对象2距离冲突点距离 (米)
     */
    private Double object2Distance;

    /**
     * 预计到达冲突点时间1 (秒)
     */
    private Integer timeToConflict1;

    /**
     * 预计到达冲突点时间2 (秒)
     */
    private Integer timeToConflict2;
    
    /**
     * 时间差 (秒)
     */
    private Double timeGap;
    
    /**
     * 事件发生时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime eventTime;
    
    /**
     * 冲突对象信息
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ConflictObject {
        
        /**
         * 对象ID
         */
        private String objectId;
        
        /**
         * 对象类型：UNMANNED_VEHICLE, AIRCRAFT, SPECIAL_VEHICLE (新增SPECIAL_VEHICLE)
         */
        private String objectType;
        
        /**
         * 对象名称（车牌号或航班号）
         */
        private String objectName;
    }
    
    /**
     * 位置信息
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Position {
        
        /**
         * 纬度
         */
        private Double latitude;
        
        /**
         * 经度
         */
        private Double longitude;
        
        /**
         * 海拔（可选）
         */
        private Double altitude;
    }
    
    /**
     * 判断是否为紧急告警
     */
    public boolean isEmergencyAlert() {
        return this.alertLevel == ConflictAlertLog.AlertLevel.EMERGENCY;
    }
    
    /**
     * 判断是否为预警
     */
    public boolean isWarning() {
        return this.alertLevel == ConflictAlertLog.AlertLevel.WARNING || this.alertType == ConflictAlertLog.AlertType.CONFLICT_WARNING;
    }
    
    /**
     * 判断是否为告警（对应 CRITICAL 级别）
     */
    public boolean isAlert() {
        return this.alertLevel == ConflictAlertLog.AlertLevel.CRITICAL || this.alertLevel == ConflictAlertLog.AlertLevel.EMERGENCY || this.alertType == ConflictAlertLog.AlertType.CONFLICT_ALERT;
    }
} 