| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | |
| | | 4 | | namespace Punch.CLI; |
| | | 5 | | |
| | | 6 | | // User-configurable settings, loaded from ~/.punch/settings.json. Also serves as |
| | | 7 | | // the JSON serialization shape. Missing or invalid values fall back to defaults. |
| | | 8 | | internal sealed class PunchSettings |
| | | 9 | | { |
| | | 10 | | // The daily workday goal in whole hours, used for the status-bar percentage. |
| | 25 | 11 | | public int TargetHours { get; set; } = 8; |
| | | 12 | | |
| | | 13 | | // Optional per-day overrides keyed by day name ("monday".."sunday", |
| | | 14 | | // case-insensitive). Days not listed fall back to TargetHours. A value of 0 |
| | | 15 | | // marks a day off (the status bar then omits the percentage). |
| | 14 | 16 | | public Dictionary<string, int>? TargetHoursByDay { get; set; } |
| | | 17 | | |
| | | 18 | | // Resolves the target for a given weekday: the per-day override if one is |
| | | 19 | | // present (clamped to >= 0), otherwise the flat TargetHours. |
| | | 20 | | public int GetTargetHours(DayOfWeek day) |
| | 6 | 21 | | { |
| | 6 | 22 | | if (TargetHoursByDay is not null) |
| | 5 | 23 | | { |
| | 25 | 24 | | foreach (var (key, value) in TargetHoursByDay) |
| | 7 | 25 | | { |
| | 7 | 26 | | if (string.Equals(key, day.ToString(), StringComparison.OrdinalIgnoreCase)) |
| | 4 | 27 | | return Math.Max(0, value); |
| | 3 | 28 | | } |
| | 1 | 29 | | } |
| | 2 | 30 | | return TargetHours; |
| | 6 | 31 | | } |
| | | 32 | | } |