package com.qaup.collision.pathconflict.model.dto;

import com.qaup.collision.pathconflict.model.entity.ConflictAlertLog;
import com.qaup.collision.common.model.MovingObject.MovingObjectType;

import lombok.Builder;
import lombok.Data;
import org.locationtech.jts.geom.Point;

import java.time.LocalDateTime;
import java.util.Optional;

/**
 * 路径冲突告警事件
 */
@Data
@Builder
public class ConflictAlertEvent {
    private Optional<Long> conflictId; // 告警日志ID
    private Optional<ConflictAlertLog.AlertType> alertType; // 告警类型
    private Optional<ConflictAlertLog.AlertLevel> alertLevel; // 告警级别
    private String message; // 告警消息
    private String object1Name; // 对象1名称
    private MovingObjectType object1Type; // 对象1类型
    private String object2Name; // 对象2名称
    private MovingObjectType object2Type; // 对象2类型
    private Point conflictPoint; // 冲突点
    private Double object1Distance; // 对象1距离冲突点距离 (米)
    private Double object2Distance; // 对象2距离冲突点距离 (米)
    private Integer estimatedTimeToConflictObj1; // 对象1预计到达冲突点的时间 (秒)
    private Integer estimatedTimeToConflictObj2; // 对象2预计到达冲突点的时间 (秒)
    private Double timeGapSeconds; // 两个对象到达冲突点的时间差 (秒)
    private LocalDateTime eventTime; // 事件发生时间

    // 辅助方法，用于判断告警级别
    public boolean isEmergencyAlert() {
        return alertLevel.isPresent() && alertLevel.get() == ConflictAlertLog.AlertLevel.EMERGENCY;
    }

    public boolean isAlert() {
        return alertLevel.isPresent() && alertLevel.get() == ConflictAlertLog.AlertLevel.CRITICAL;
    }

    public boolean isWarning() {
        return alertLevel.isPresent() && alertLevel.get() == ConflictAlertLog.AlertLevel.WARNING;
    }

    public Double getConflictPointLatitude() {
        return conflictPoint != null ? conflictPoint.getY() : null;
    }

    public Double getConflictPointLongitude() {
        return conflictPoint != null ? conflictPoint.getX() : null;
    }
} 