package main

import (
	"github.com/mattermost/mattermost/server/public/model"
)

// broadcastUpdate sends a WebSocket event to all clients viewing the given channel.
// The event is auto-prefixed by the SDK to "custom_com.openclaw.livestatus_update".
func (p *Plugin) broadcastUpdate(channelID string, data SessionData) {
	payload := map[string]interface{}{
		"post_id":      data.PostID,
		"session_key":  data.SessionKey,
		"agent_id":     data.AgentID,
		"status":       data.Status,
		"lines":        data.Lines,
		"elapsed_ms":   data.ElapsedMs,
		"token_count":  data.TokenCount,
		"children":     data.Children,
		"start_time_ms": data.StartTimeMs,
	}

	p.API.PublishWebSocketEvent("update", payload, &model.WebsocketBroadcast{
		ChannelId: channelID,
	})
}
