66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package domain
|
|
|
|
import "time"
|
|
|
|
// UserID is a strongly-typed identifier for users.
|
|
type UserID string
|
|
|
|
// String returns the string representation of the UserID.
|
|
func (id UserID) String() string {
|
|
return string(id)
|
|
}
|
|
|
|
// Preferences holds the user's preference settings.
|
|
type Preferences struct {
|
|
Theme string `json:"theme"`
|
|
Language string `json:"language"`
|
|
Notifications NotificationSettings `json:"notifications"`
|
|
}
|
|
|
|
// NotificationSettings holds notification-related preferences.
|
|
type NotificationSettings struct {
|
|
Email bool `json:"email"`
|
|
Push bool `json:"push"`
|
|
Digest string `json:"digest"`
|
|
}
|
|
|
|
// UserPreferences is the domain entity representing a user's full preference record.
|
|
type UserPreferences struct {
|
|
UserID UserID
|
|
Preferences Preferences
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
// DefaultPreferences returns the default preference values.
|
|
func DefaultPreferences() Preferences {
|
|
return Preferences{
|
|
Theme: "system",
|
|
Language: "en",
|
|
Notifications: NotificationSettings{
|
|
Email: true,
|
|
Push: true,
|
|
Digest: "weekly",
|
|
},
|
|
}
|
|
}
|
|
|
|
// Allowed values.
|
|
var (
|
|
allowedThemes = map[string]bool{"light": true, "dark": true, "system": true}
|
|
allowedDigests = map[string]bool{"daily": true, "weekly": true, "never": true}
|
|
)
|
|
|
|
// Validate checks that all preference values are valid.
|
|
func (p *Preferences) Validate() error {
|
|
if !allowedThemes[p.Theme] {
|
|
return ErrInvalidTheme
|
|
}
|
|
if p.Language == "" {
|
|
return ErrInvalidLanguage
|
|
}
|
|
if !allowedDigests[p.Notifications.Digest] {
|
|
return ErrInvalidDigest
|
|
}
|
|
return nil
|
|
}
|