package ports

import (
	"context"

	sharedEvents "github.com/nexuscrm/shared/pkg/events"
)

// EventHandler is a function that handles an event
type EventHandler func(ctx context.Context, payload interface{}) error

// EventPublisher provides event publishing capabilities.
// Implementations should handle async event dispatching.
type EventPublisher interface {
	// Subscribe registers a handler for a specific event type.
	Subscribe(eventType sharedEvents.EventType, handler EventHandler) func()

	// Publish dispatches an event to all registered handlers.
	// Returns an error if any handler fails.
	Publish(ctx context.Context, eventType sharedEvents.EventType, payload interface{}) error

	// PublishAsyncWithContext dispatches an event asynchronously with trace context propagation.
	// The parent context's trace_id and traceparent are preserved across the async boundary.
	PublishAsyncWithContext(ctx context.Context, eventType sharedEvents.EventType, payload interface{})
}
