56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package ports
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"galaxy/user/internal/domain/common"
|
|
)
|
|
|
|
const (
|
|
// DeclaredCountryChangedEventType identifies declared-country change events
|
|
// in the shared auxiliary event stream.
|
|
DeclaredCountryChangedEventType = "user.declared_country.changed"
|
|
)
|
|
|
|
// DeclaredCountryChangedEvent stores one auxiliary declared-country change
|
|
// notification emitted after a successful source-of-truth update.
|
|
type DeclaredCountryChangedEvent struct {
|
|
// UserID identifies the user whose current declared country changed.
|
|
UserID common.UserID
|
|
|
|
// TraceID stores the optional OpenTelemetry trace identifier propagated
|
|
// from the current request context.
|
|
TraceID string
|
|
|
|
// DeclaredCountry stores the latest effective declared country.
|
|
DeclaredCountry common.CountryCode
|
|
|
|
// UpdatedAt stores the persisted account mutation timestamp.
|
|
UpdatedAt time.Time
|
|
|
|
// Source stores the machine-readable upstream mutation source.
|
|
Source common.Source
|
|
}
|
|
|
|
// Validate reports whether event is structurally complete.
|
|
func (event DeclaredCountryChangedEvent) Validate() error {
|
|
if err := validateEventEnvelope("declared-country changed event", event.UserID, event.UpdatedAt, event.Source, event.TraceID); err != nil {
|
|
return err
|
|
}
|
|
if err := event.DeclaredCountry.Validate(); err != nil {
|
|
return fmt.Errorf("declared-country changed event declared country: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// DeclaredCountryChangedPublisher publishes auxiliary declared-country change
|
|
// notifications after source-of-truth account updates.
|
|
type DeclaredCountryChangedPublisher interface {
|
|
// PublishDeclaredCountryChanged propagates one committed declared-country
|
|
// change event.
|
|
PublishDeclaredCountryChanged(ctx context.Context, event DeclaredCountryChangedEvent) error
|
|
}
|