package usersettings import ( "context" "time" "velox-bot/internal/db/repos/usersettingsrepo" ) type Service struct { repo *usersettingsrepo.Repo } func New(repo *usersettingsrepo.Repo) *Service { return &Service{repo: repo} } func (s *Service) SetTimezone(ctx context.Context, userID int64, zone string) error { // validate zone before storing if _, err := time.LoadLocation(zone); err != nil { return err } return s.repo.SetTimezone(ctx, userID, zone) } // GetTimezone returns the user's location (or UTC) and the zone string and a flag indicating if it was user-defined. func (s *Service) GetTimezone(ctx context.Context, userID int64) (*time.Location, string, bool, error) { zone, ok, err := s.repo.GetTimezone(ctx, userID) if err != nil { return time.UTC, "UTC", false, err } if !ok || zone == "" { return time.UTC, "UTC", false, nil } loc, err := time.LoadLocation(zone) if err != nil { // fallback to UTC but indicate not user-defined return time.UTC, "UTC", false, nil } return loc, zone, true, nil }