package com.qaup.collision.websocket.event;

import com.qaup.collision.websocket.message.GeofenceAlertPayload;
import com.qaup.collision.websocket.message.MessageTypeConstants;
import lombok.Data;
import lombok.Builder;

import java.util.UUID;

/**
 * 电子围栏告警WebSocket事件
 * 用于通知前端无人车电子围栏访问情况
 * 
 * @author qaup-collision
 * @date 2025-01-15
 */
@Data
@Builder
public class GeofenceAlertWebSocketEvent implements WebSocketEvent {

    /**
     * 事件唯一标识
     */
    private final String eventId;

    /**
     * 事件时间戳（微秒级）
     */
    private final long timestamp;

    /**
     * 电子围栏告警载荷数据
     */
    private final GeofenceAlertPayload payload;

    /**
     * 创建电子围栏告警WebSocket事件
     * 
     * @param payload 告警事件载荷
     * @return WebSocket事件实例
     */
    public static GeofenceAlertWebSocketEvent create(GeofenceAlertPayload payload) {
        return GeofenceAlertWebSocketEvent.builder()
                .eventId(UUID.randomUUID().toString())
                .timestamp(java.time.Instant.now().toEpochMilli() * 1000) // 微秒级绝对时间戳
                .payload(payload)
                .build();
    }

    @Override
    public String getEventType() {
        return MessageTypeConstants.GEOFENCE_ALERT;
    }

    @Override
    public Object getPayload() {
        return payload;
    }
}