package im

import (
	"strings"

	storeim "github.com/tidbcloud/AgentTeam/internal/store/im"
)

// EmitWorkspaceAppsUpdated broadcasts a role-sensitive App catalog refresh.
// The payload deliberately carries no App identifier: a private-App mutation
// must not disclose that App's existence to an ordinary workspace member.
// Every browser re-reads its own server-authorized catalog and installation
// views instead.
func (emitter *LiveEventEmitter) EmitWorkspaceAppsUpdated(workspaceID string) {
	if emitter == nil || emitter.hub == nil {
		return
	}
	workspaceID = strings.TrimSpace(workspaceID)
	if workspaceID == "" {
		return
	}
	emitter.hub.PublishWorkspaceLiveOnlyEvent(storeim.StreamEvent{
		WorkspaceID: workspaceID,
		Type:        liveEventTypeWorkspaceAppsUpdated,
		Payload:     map[string]any{"workspaceId": workspaceID},
	})
}
