| | | 1 | | namespace Pomodoro.Web.Models; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Configuration settings for timer durations and preferences |
| | | 5 | | /// Values are automatically clamped to valid ranges on set. |
| | | 6 | | /// </summary> |
| | | 7 | | public class TimerSettings |
| | | 8 | | { |
| | 2463 | 9 | | private int _pomodoroMinutes = Constants.Timer.DefaultPomodoroMinutes; |
| | 2463 | 10 | | private int _shortBreakMinutes = Constants.Timer.DefaultShortBreakMinutes; |
| | 2463 | 11 | | private int _longBreakMinutes = Constants.Timer.DefaultLongBreakMinutes; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Pomodoro duration in minutes. Clamped to valid range. |
| | | 15 | | /// </summary> |
| | | 16 | | public int PomodoroMinutes |
| | | 17 | | { |
| | 2598 | 18 | | get => _pomodoroMinutes; |
| | 508 | 19 | | set => _pomodoroMinutes = Math.Clamp(value, Constants.Timer.MinPomodoroMinutes, Constants.Timer.MaxPomodoroMinut |
| | | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Short break duration in minutes. Clamped to valid range. |
| | | 24 | | /// </summary> |
| | | 25 | | public int ShortBreakMinutes |
| | | 26 | | { |
| | 2256 | 27 | | get => _shortBreakMinutes; |
| | 482 | 28 | | set => _shortBreakMinutes = Math.Clamp(value, Constants.Timer.MinBreakMinutes, Constants.Timer.MaxBreakMinutes); |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Long break duration in minutes. Clamped to valid range. |
| | | 33 | | /// </summary> |
| | | 34 | | public int LongBreakMinutes |
| | | 35 | | { |
| | 2239 | 36 | | get => _longBreakMinutes; |
| | 480 | 37 | | set => _longBreakMinutes = Math.Clamp(value, Constants.Timer.MinBreakMinutes, Constants.Timer.MaxBreakMinutes); |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Gets the duration in minutes for the specified session type. |
| | | 42 | | /// Centralizes session duration logic to reduce code duplication. |
| | | 43 | | /// </summary> |
| | | 44 | | /// <param name="sessionType">The type of session</param> |
| | | 45 | | /// <returns>Duration in minutes for the session type</returns> |
| | 168 | 46 | | public int GetDurationMinutes(SessionType sessionType) => sessionType switch |
| | 168 | 47 | | { |
| | 117 | 48 | | SessionType.Pomodoro => PomodoroMinutes, |
| | 29 | 49 | | SessionType.ShortBreak => ShortBreakMinutes, |
| | 20 | 50 | | SessionType.LongBreak => LongBreakMinutes, |
| | 2 | 51 | | _ => PomodoroMinutes |
| | 168 | 52 | | }; |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// Gets the duration in seconds for the specified session type. |
| | | 56 | | /// Convenience method that converts minutes to seconds. |
| | | 57 | | /// </summary> |
| | | 58 | | /// <param name="sessionType">The type of session</param> |
| | | 59 | | /// <returns>Duration in seconds for the session type</returns> |
| | | 60 | | public int GetDurationSeconds(SessionType sessionType) => |
| | 131 | 61 | | GetDurationMinutes(sessionType) * Constants.TimeConversion.SecondsPerMinute; |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// Whether sound notifications are enabled |
| | | 65 | | /// </summary> |
| | 5114 | 66 | | public bool SoundEnabled { get; set; } = true; |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Whether browser notifications are enabled |
| | | 70 | | /// </summary> |
| | 4999 | 71 | | public bool NotificationsEnabled { get; set; } = true; |
| | | 72 | | |
| | | 73 | | /// <summary> |
| | | 74 | | /// Whether to automatically start the next timer (pomodoro or break) after the current one completes |
| | | 75 | | /// </summary> |
| | 5178 | 76 | | public bool AutoStartEnabled { get; set; } = true; |
| | | 77 | | |
| | 2463 | 78 | | private int _autoStartDelaySeconds = Constants.Timer.DefaultAutoStartDelaySeconds; |
| | | 79 | | |
| | | 80 | | /// <summary> |
| | | 81 | | /// Delay in seconds before auto-starting. Clamped to valid range (3-60 seconds). |
| | | 82 | | /// </summary> |
| | | 83 | | public int AutoStartDelaySeconds |
| | | 84 | | { |
| | 2031 | 85 | | get => _autoStartDelaySeconds; |
| | 558 | 86 | | set => _autoStartDelaySeconds = Math.Clamp(value, Constants.Timer.MinAutoStartDelaySeconds, Constants.Timer.MaxA |
| | | 87 | | } |
| | | 88 | | |
| | | 89 | | /// <summary> |
| | | 90 | | /// Compares this settings instance with another for equality |
| | | 91 | | /// </summary> |
| | | 92 | | public bool Equals(TimerSettings? other) |
| | 579 | 93 | | { |
| | 743 | 94 | | if (other is null) return false; |
| | 415 | 95 | | return PomodoroMinutes == other.PomodoroMinutes |
| | 415 | 96 | | && ShortBreakMinutes == other.ShortBreakMinutes |
| | 415 | 97 | | && LongBreakMinutes == other.LongBreakMinutes |
| | 415 | 98 | | && SoundEnabled == other.SoundEnabled |
| | 415 | 99 | | && NotificationsEnabled == other.NotificationsEnabled |
| | 415 | 100 | | && AutoStartEnabled == other.AutoStartEnabled |
| | 415 | 101 | | && AutoStartDelaySeconds == other.AutoStartDelaySeconds; |
| | 579 | 102 | | } |
| | | 103 | | |
| | | 104 | | /// <inheritdoc/> |
| | 3 | 105 | | public override bool Equals(object? obj) => Equals(obj as TimerSettings); |
| | | 106 | | |
| | | 107 | | /// <summary> |
| | | 108 | | /// Equality operator for comparing two TimerSettings instances |
| | | 109 | | /// </summary> |
| | | 110 | | public static bool operator ==(TimerSettings? left, TimerSettings? right) |
| | 510 | 111 | | { |
| | 635 | 112 | | if (left is null) return right is null; |
| | 385 | 113 | | return left.Equals(right); |
| | 510 | 114 | | } |
| | | 115 | | |
| | | 116 | | /// <summary> |
| | | 117 | | /// Inequality operator for comparing two TimerSettings instances |
| | | 118 | | /// </summary> |
| | | 119 | | public static bool operator !=(TimerSettings? left, TimerSettings? right) |
| | 419 | 120 | | { |
| | 419 | 121 | | return !(left == right); |
| | 419 | 122 | | } |
| | | 123 | | |
| | | 124 | | /// <inheritdoc/> |
| | 9 | 125 | | public override int GetHashCode() => HashCode.Combine( |
| | 9 | 126 | | PomodoroMinutes, |
| | 9 | 127 | | ShortBreakMinutes, |
| | 9 | 128 | | LongBreakMinutes, |
| | 9 | 129 | | SoundEnabled, |
| | 9 | 130 | | NotificationsEnabled, |
| | 9 | 131 | | AutoStartEnabled, |
| | 9 | 132 | | AutoStartDelaySeconds); |
| | | 133 | | |
| | | 134 | | /// <summary> |
| | | 135 | | /// Creates a deep copy of this settings instance |
| | | 136 | | /// </summary> |
| | | 137 | | /// <returns>A new TimerSettings instance with the same values</returns> |
| | 292 | 138 | | public TimerSettings Clone() => new() |
| | 292 | 139 | | { |
| | 292 | 140 | | PomodoroMinutes = PomodoroMinutes, |
| | 292 | 141 | | ShortBreakMinutes = ShortBreakMinutes, |
| | 292 | 142 | | LongBreakMinutes = LongBreakMinutes, |
| | 292 | 143 | | SoundEnabled = SoundEnabled, |
| | 292 | 144 | | NotificationsEnabled = NotificationsEnabled, |
| | 292 | 145 | | AutoStartEnabled = AutoStartEnabled, |
| | 292 | 146 | | AutoStartDelaySeconds = AutoStartDelaySeconds |
| | 292 | 147 | | }; |
| | | 148 | | } |