Skip to main content

kasl/libs/messages/
types.rs

1//! Message type definitions for the kasl application.
2//!
3//! Defines the central `Message` enum that represents all user-facing messages with type safety and compile-time verification.
4//!
5//! ## Features
6//!
7//! - **Type Safety**: All messages are strongly typed with appropriate parameters
8//! - **Centralization**: Single enum captures all application messaging needs  
9//! - **Extensibility**: Easy addition of new message types and categories
10//! - **Organization**: Logical grouping by functional categories
11//! - **Internationalization**: Structure supports future localization efforts
12//!
13//! ## Usage
14//!
15//! ```rust
16//! use kasl::libs::messages::types::Message;
17//! use kasl::{msg_info, msg_error, msg_success};
18//!
19//! msg_success!(Message::TaskCreated);
20//! msg_error!(Message::ConfigSaveError);
21//! msg_info!(Message::MonitorStarted {
22//!     pause_threshold: 60,
23//!     poll_interval: 500, 
24//!     activity_threshold: 30,
25//! });
26//! ```
27
28/// Comprehensive message enumeration for all user-facing communication.
29///
30/// This enum represents every type of message that the kasl application can
31/// present to users. It provides a type-safe way to handle all application
32/// communication while ensuring consistent formatting and proper parameter
33/// handling across all components.
34///
35/// ## Message Categories
36///
37/// The enum is organized into logical categories that correspond to different
38/// areas of application functionality. Each category groups related messages
39/// to improve maintainability and make it easier to understand the scope
40/// of each functional area.
41///
42/// ## Parameter Conventions
43///
44/// - **String Parameters**: Used for names, descriptions, and user-provided text
45/// - **Numeric Parameters**: Used for counts, IDs, and measurements
46/// - **Status Parameters**: Used for system states and operation results
47/// - **Structured Parameters**: Named fields for complex message data
48///
49/// ## Adding New Messages
50///
51/// When adding new message variants:
52/// 1. Choose the appropriate category section
53/// 2. Use descriptive names that clearly indicate the message purpose
54/// 3. Include necessary parameters with appropriate types
55/// 4. Add corresponding text in the `Display` implementation
56/// 5. Document the message purpose and usage context
57///
58/// ## Backward Compatibility
59///
60/// The enum is designed to maintain backward compatibility:
61/// - New variants can be added without breaking existing code
62/// - Parameter changes should be additive when possible
63/// - Deprecated messages can be maintained for transition periods
64#[derive(Debug, Clone)]
65pub enum Message {
66    // === AUTOSTART MESSAGES ===
67    AutostartEnabled,
68    AutostartEnabledUser,
69    AutostartDisabled,
70    AutostartAlreadyDisabled,
71    AutostartEnableFailed(String),
72    AutostartDisableFailed(String),
73    AutostartStatus(String),
74    AutostartNotImplemented,
75    AutostartRequiresAdmin,
76    AutostartCheckingAlternative,
77
78    // === TASK MESSAGES ===
79    TaskCreated,
80    TaskUpdated,
81    TaskDeleted,
82    TaskNotFound,
83    TaskCreateFailed,
84    TaskUpdateFailed,
85    TaskDeleteFailed,
86    TasksDeletedCount(usize),
87    TasksNotFoundForDate(String),
88    TasksNotFoundSad,
89    TasksHeader,
90    TasksIncompleteHeader,
91    TasksGitlabHeader,
92    TasksJiraHeader,
93    /// Summary line before unified discovery MultiSelect
94    TasksDiscoverySummary {
95        incomplete: usize,
96        jira: usize,
97        gitlab: usize,
98    },
99    /// Non-selectable separator between incomplete and other items
100    TasksDiscoverySeparator,
101    TasksDiscoverySearchingIncomplete,
102    TasksDiscoveryFetchingExternal,
103    NoTaskIdsProvided,
104    TasksNotFoundForIds(Vec<i32>),
105    TasksToBeDeleted,
106    ConfirmDeleteTask,
107    ConfirmDeleteTasks(usize),
108    ConfirmDeleteAllTodayTasks(usize),
109    ConfirmDeleteAllTodayTasksFinal,
110    NoTasksForToday,
111    TaskNotFoundWithId(i32),
112    CurrentTaskState,
113    TaskEditPreview,
114    ConfirmTaskUpdate,
115    NoChangesDetected,
116    NoTasksSelected,
117    SelectTasksToEdit,
118    EditingTask(String),
119    TaskUpdatedWithName(String),
120    TaskSkippedNoChanges(String),
121    TaskEditingCompleted,
122    PromptTaskNameEdit,
123    PromptTaskCommentEdit,
124    PromptTaskCompletenessEdit,
125    TaskCompletenessRange,
126
127    // === WORKDAY MESSAGES ===
128    WorkdayEnded,
129    WorkdayNotFound,
130    WorkdayNotFoundForDate(String),
131    WorkdayCreateFailed,
132    WorkdayStarting(String),                    // date
133    WorkdayCouldNotFindAfterFinalizing(String), // date
134
135    // === CONFIGURATION MESSAGES ===
136    ConfigSaved,
137    ConfigDeleted,
138    ConfigLoaded,
139    ConfigFileNotFound,
140    ConfigParseError,
141    ConfigSaveError,
142    ConfigModuleGitLab,
143    ConfigModuleJira,
144    ConfigModuleSiServer,
145    ConfigModuleMonitor,
146    ConfigModuleServer,
147    ConfigModuleProductivity,
148    ConfigModuleTaskDiscovery,
149    TaskDiscoveryIgnoreListHeader,
150    TaskDiscoveryIgnoreListEmpty,
151    TaskDiscoveryIgnoreNameAdded(String),
152    TaskDiscoveryIgnoreNameExists(String),
153    TaskDiscoveryIgnoreNamesAdded(usize),
154
155    // === REPORT MESSAGES ===
156    DailyReportSent(String),   // date
157    MonthlyReportSent(String), // date
158    MonthlyReportTriggered,
159    ReportSendFailed(String),        // status
160    MonthlyReportSendFailed(String), // status
161    ReportHeader(String),            // date
162    WorkingHoursForMonth(String),    // month/year
163
164    // === EXPORT MESSAGES ===
165    ExportingData(String, String), // data type, format
166    ExportCompleted(String),       // file path
167    ExportingAllData,
168    ExportFailed(String), // error
169
170    // === TEMPLATE MESSAGES ===
171    TemplateCreated(String),
172    TemplateUpdated(String),
173    TemplateDeleted(String),
174    TemplateNotFound(String),
175    TemplateAlreadyExists(String),
176    TemplateCreateFailed,
177    NoTemplatesFound,
178    TemplateListHeader,
179    SelectTemplateToEdit,
180    SelectTemplateToDelete,
181    ConfirmDeleteTemplate(String),
182    EditingTemplate(String),
183    NoTemplatesMatchingQuery(String),
184    TemplateSearchResults(String),
185    SelectTemplateAction,
186    PromptTemplateName,
187    PromptTemplateTaskName,
188    PromptTemplateComment,
189    PromptTemplateCompleteness,
190    CreatingTaskFromTemplate(String),
191    SelectTemplate,
192    CreateTemplateFirst,
193
194    // === TAG MESSAGES ===
195    TagCreated(String),
196    TagUpdated(String),
197    TagDeleted(String),
198    TagNotFound(String),
199    TagAlreadyExists(String),
200    NoTagsFound,
201    TagListHeader,
202    EditingTag(String),
203    SelectTagAction,
204    SelectTagToEdit,
205    SelectTagToDelete,
206    ConfirmDeleteTag(String),
207    ConfirmDeleteTagWithTasks(String, usize), // tag name, task count
208    PromptTagName,
209    PromptTagColor,
210    NoTasksWithTag(String),
211    TasksWithTag(String),
212    TagsAddedToTask(String),
213
214    // === SHORT INTERVALS MESSAGES ===
215    ShortIntervalsDetected(usize, String), // count, total duration
216    NoShortIntervalsFound(u64),            // min_minutes
217    ShortIntervalsToRemove(usize), // count
218    RemovingPauses(usize),         // count
219    ShortIntervalsCleared(usize),  // deleted count
220    NoRemovablePausesFound,
221    UpdatedReport,
222    PromptMinWorkInterval,
223
224    // === TIME ADJUSTMENT MESSAGES ===
225    SelectAdjustmentMode,
226    PromptAdjustmentMinutes,
227    PromptPauseStartTime,
228    ConfirmTimeAdjustment,
229    TimeAdjustmentApplied,
230    AdjustmentPreview,
231    InvalidAdjustmentTooMuchTime,
232    InvalidPauseOutsideWorkday,
233    WorkdayUpdateFailed,
234
235    // === PAUSE MESSAGES ===
236    PausesTitle(String),
237
238    // === MONITOR MESSAGES ===
239    MonitorStarted {
240        pause_threshold: u64,
241        poll_interval: u64,
242        activity_threshold: u64,
243    },
244    MonitorStopped,
245    MonitorStartFailed,
246    MonitorStopFailed,
247    MonitorExitedNormally,
248    MonitorShuttingDown,
249    MonitorError(String),
250    MonitorTaskPanicked(String),
251    PauseStarted,
252    PauseEnded,
253
254    // === WATCHER/DAEMON MESSAGES ===
255    WatcherStarted(u32), // PID
256    WatcherStopped(u32), // PID
257    WatcherStoppedSuccessfully,
258    WatcherNotRunning,
259    WatcherNotRunningPidNotFound,
260    WatcherStartingForeground,
261    WatcherStoppingExisting(String),     // PID
262    WatcherFailedToStopExisting(String), // error
263    WatcherFailedToStop(u32),            // PID
264    WatcherReceivedSigterm,
265    WatcherReceivedSigint,
266    WatcherReceivedCtrlC,
267    WatcherCtrlCListenFailed(String), // error
268    WatcherSignalHandlingNotSupported,
269    DaemonModeNotSupported,
270    FailedToGetCurrentExecutable,
271    FailedToCreateSigtermHandler,
272    FailedToCreateSigintHandler,
273
274    // === UPDATE MESSAGES ===
275    UpdateAvailable {
276        app_name: String,
277        latest: String,
278    },
279    UpdateCompleted {
280        app_name: String,
281        version: String,
282    },
283    NoUpdateRequired,
284    UpdateDownloadUrlNotSet,
285    WatcherStoppingForUpdate,
286    WatcherRestartingAfterUpdate,
287    WatcherStoppingForConfig,
288    WatcherRestartingAfterConfig,
289    WatcherRestarted,
290    WatcherRestartFailed { error: String },
291    UpdateBinaryNotFoundInArchive,
292
293    // === AUTHENTICATION MESSAGES ===
294    WrongPassword(i32), // attempt count
295    InvalidCredentials,
296    SessionExpired,
297    AuthenticationFailed(String), // service name
298    JiraAuthenticateFailed,
299    LoginFailed,
300    CredentialsNotSet,
301
302    // === API MESSAGES ===
303    ApiConnectionFailed,
304    ApiAuthFailed,
305    ApiRequestFailed,
306    GitlabFetchFailed(String),  // error message
307    GitlabUserIdFailed(String), // error message
308    JiraFetchFailed(String),    // error message
309    SiServerConfigNotFound,
310    SiServerSessionFailed(String),          // error message
311    SiServerRestDatesFailed(String),        // error message
312    SiServerRestDatesParsingFailed(String), // error message
313
314    // === DATABASE MESSAGES ===
315    DbConnectionFailed,
316    DbQueryFailed,
317    DbMigrationFailed,
318    DatabaseOperationFailed { operation: String, error: String },
319    NoIdSet,
320
321    // === FILE SYSTEM MESSAGES ===
322    FileNotFound,
323    FileReadError,
324    FileWriteError,
325    InvalidPidFileContent,
326    DataStoragePathError,
327
328    // === SYSTEM/PATH MESSAGES ===
329    PathConfigured,
330    PathConfigWarning { error: String },
331    PathQueryFailed(String), // status
332    PathSetFailed,
333    PathRegistryQueryError { status: String },
334    PathRegistryUpdateError { status: String, stderr: String },
335    FailedToJoinPaths,
336    FailedToExecuteRegQuery,
337    FailedToParseRegOutput,
338    FailedToGetPathFromReg,
339    FailedToExecuteRegSet,
340    FailedToOpenProcess(u32),      // error code
341    FailedToTerminateProcess(u32), // error code
342    ProcessNotFound,
343    ProcessTerminationNotSupported,
344
345    // === PRODUCTIVITY MESSAGES ===
346    MonthlyProductivity(f64), // percentage
347    LowProductivityWarning {
348        current: f64,
349        threshold: f64,
350        needed_break_minutes: u64,
351    },
352    ProductivityTooLowToSend {
353        current: f64,
354        threshold: f64,
355        needed_break_minutes: u64,
356    },
357    BreakCreated {
358        start_time: String,
359        end_time: String,
360        duration_minutes: u64,
361    },
362    BreakCreateFailed(String),
363    BreakSuggestionCommand {
364        auto_minutes: u64,
365    },
366    BreakInteractivePrompt,
367    BreakDurationPrompt {
368        min_duration: u64,
369        max_duration: u64,
370    },
371    BreakPlacementOptions,
372    BreakOptionSelected(usize),
373    BreakConflictsWithPauses,
374    NoValidBreakPlacement,
375    ProductivityRecalculated(f64),
376
377    // === ENCRYPTION/SECRET MESSAGES ===
378    EncryptionKeyMustBeSet,
379    EncryptionIvMustBeSet,
380
381    // === PROMPTS ===
382    PromptTaskName,
383    TaskNameMergedFromPaste,
384    PromptTaskComment,
385    PromptTaskCompleteness,
386    PromptGitlabToken,
387    PromptGitlabUrl,
388    PromptJiraLogin,
389    PromptJiraUrl,
390    PromptJiraPassword,
391    PromptSiLogin,
392    PromptSiAuthUrl,
393    PromptSiApiUrl,
394    PromptSiPassword,
395    PromptMinPauseDuration,
396    PromptPauseThreshold,
397    PromptPollInterval,
398    PromptActivityThreshold,
399    PromptMinProductivityThreshold,
400    PromptWorkdayHours,
401    PromptMinWorkdayFraction,
402    PromptMinBreakDuration,
403    PromptMaxBreakDuration,
404    PromptServerApiUrl,
405    PromptServerAuthToken,
406    PromptConfirmDelete,
407    PromptSelectOptions,
408    PromptSelectModules,
409    PromptSelectTasks,
410    PromptSelectTasksToEdit,
411    PromptSelectTasksToImport,
412    PromptSelectTasksToIgnore,
413    PromptSelectIgnoreNamesToRemove,
414    PromptAddIgnoreName,
415
416    // === GENERAL MESSAGES ===
417    OperationCompleted,
418    OperationCancelled,
419    DataExported,
420    BackupCreated,
421    InvalidInput,
422    PermissionDenied,
423
424    // === ERROR LOGGING ===
425    ErrorSendingEvents(String),        // error message
426    ErrorSendingMonthlyReport(String), // error message
427    ErrorInRdevListener(String),       // error message
428    ErrorRequestingRestDates(String),  // error message
429
430    // === SPECIFIC UI MESSAGES ===
431    SelectingTask(String),           // task name
432    SelectedTaskFormat(String, i32), // task name, completeness
433
434    // === MIGRATION MESSAGES ===
435    MigrationsFound(usize),        // count
436    RunningMigration(u32, String), // version, name
437    MigrationCompleted(u32),       // version
438    MigrationFailed(u32, String),  // version, error
439    AllMigrationsCompleted,
440    DatabaseVersion(u32),
441    DatabaseUpToDate,
442    DatabaseNeedsUpdate,
443    MigrationHistory,
444    NothingToRollback,
445    RollingBack(u32, u32),  // from, to
446    RollbackCompleted(u32), // version
447}