package memory

import (
	"context"

	"github.com/rwadurian/mpc-system/pkg/logger"
	"github.com/rwadurian/mpc-system/services/session-coordinator/application/ports/output"
	"go.uber.org/zap"
)

// EventPublisherAdapter implements MessageBrokerPort using in-memory logging
// Events are logged but not distributed (suitable for single-instance deployment)
type EventPublisherAdapter struct{}

// NewEventPublisherAdapter creates a new in-memory event publisher
func NewEventPublisherAdapter() output.MessageBrokerPort {
	return &EventPublisherAdapter{}
}

// PublishEvent logs the event
func (p *EventPublisherAdapter) PublishEvent(ctx context.Context, topic string, event interface{}) error {
	logger.Info("Session event published",
		zap.String("topic", topic),
		zap.Any("event", event))
	return nil
}

// PublishMessage logs the message
func (p *EventPublisherAdapter) PublishMessage(ctx context.Context, partyID string, message interface{}) error {
	logger.Debug("Message published to party",
		zap.String("party_id", partyID))
	return nil
}

// Subscribe returns a nil channel (no actual subscription in single-instance mode)
func (p *EventPublisherAdapter) Subscribe(ctx context.Context, topic string) (<-chan []byte, error) {
	// Return a closed channel since we don't have actual pub/sub
	ch := make(chan []byte)
	close(ch)
	return ch, nil
}

// Close is a no-op for in-memory publisher
func (p *EventPublisherAdapter) Close() error {
	return nil
}

// Ensure interface compliance
var _ output.MessageBrokerPort = (*EventPublisherAdapter)(nil)
