package com.qaup.collision.websocket.event;

import lombok.Data;
import lombok.Builder;

import java.util.UUID;

import com.qaup.collision.websocket.message.MessageTypeConstants;
import com.qaup.collision.websocket.message.RuleExecutionStatusPayload;

/**
 * 规则执行状态WebSocket事件
 * 用于通知前端规则执行状态变化
 * 
 * @author AI Assistant
 * @since 2025-01-17
 */
@Data
@Builder
public class RuleExecutionStatusWebSocketEvent implements WebSocketEvent {

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

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

    /**
     * 规则执行状态载荷数据
     */
    private final RuleExecutionStatusPayload payload;

    /**
     * 创建规则执行状态WebSocket事件
     * 
     * @param payload 执行状态载荷
     * @return WebSocket事件实例
     */
    public static RuleExecutionStatusWebSocketEvent create(RuleExecutionStatusPayload payload) {
        return RuleExecutionStatusWebSocketEvent.builder()
                .eventId(UUID.randomUUID().toString())
                .timestamp(java.time.Instant.now().toEpochMilli() * 1000) // 微秒级绝对时间戳
                .payload(payload)
                .build();
    }

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

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