diff --git a/src/HikvisionAttendanceManager.App/Models/ConnectionTestOutcome.cs b/src/HikvisionAttendanceManager.App/Models/ConnectionTestOutcome.cs new file mode 100644 index 0000000..f82b192 --- /dev/null +++ b/src/HikvisionAttendanceManager.App/Models/ConnectionTestOutcome.cs @@ -0,0 +1,31 @@ +namespace HikvisionAttendanceManager.App.Models; + +public enum ConnectionTestOutcome +{ + Online, + AuthenticationFailed, + ApiResponseError, + Timeout, + Offline, + CredentialsMissing +} + +public static class ConnectionTestOutcomeExtensions +{ + public static string ToDashboardStatus(this ConnectionTestOutcome outcome) => outcome switch + { + ConnectionTestOutcome.Online => "Online", + ConnectionTestOutcome.ApiResponseError => "API Error", + ConnectionTestOutcome.AuthenticationFailed => "Authentication Failed", + ConnectionTestOutcome.Timeout => "Offline", + ConnectionTestOutcome.Offline => "Offline", + ConnectionTestOutcome.CredentialsMissing => "Not Tested", + _ => "Not Tested" + }; + + public static bool CountsAsOnline(this ConnectionTestOutcome outcome) => + outcome is ConnectionTestOutcome.Online or ConnectionTestOutcome.ApiResponseError; + + public static bool CountsAsOffline(this ConnectionTestOutcome outcome) => + outcome is ConnectionTestOutcome.Timeout or ConnectionTestOutcome.Offline; +}