package events

import (
	"context"
	"strings"
)

type currentOutboxEventIDContextKey struct{}

// WithCurrentOutboxEventID binds the exact durable event whose effect
// transaction is publishing subscribers. Downstream durable producers use it
// only as idempotency identity; it is never exposed in public event payloads.
func WithCurrentOutboxEventID(ctx context.Context, eventID string) context.Context {
	if ctx == nil {
		ctx = context.Background()
	}
	return context.WithValue(ctx, currentOutboxEventIDContextKey{}, strings.TrimSpace(eventID))
}

// CurrentOutboxEventID returns only the event identity explicitly installed by
// the outbox effect transaction. There is no request-ID or process-local
// fallback.
func CurrentOutboxEventID(ctx context.Context) (string, bool) {
	if ctx == nil {
		return "", false
	}
	eventID, _ := ctx.Value(currentOutboxEventIDContextKey{}).(string)
	eventID = strings.TrimSpace(eventID)
	return eventID, eventID != ""
}
