| | | 1 | | namespace RoleRadar.Application.Insights; |
| | | 2 | | |
| | | 3 | | /// <summary>The two windows the Insights page offers. The wire names are <see cref="InsightsWindows.Last90DaysName"/> a |
| | | 4 | | public enum InsightsWindow |
| | | 5 | | { |
| | | 6 | | Last90Days, |
| | | 7 | | AllTime |
| | | 8 | | } |
| | | 9 | | |
| | | 10 | | /// <summary>Wire names for <see cref="InsightsWindow"/> (a string enum in the OpenAPI schema). Matching is exact and ca |
| | | 11 | | public static class InsightsWindows |
| | | 12 | | { |
| | | 13 | | public const string Last90DaysName = "last90Days"; |
| | | 14 | | public const string AllTimeName = "allTime"; |
| | | 15 | | |
| | 32 | 16 | | public static IReadOnlyList<string> Names { get; } = [Last90DaysName, AllTimeName]; |
| | | 17 | | |
| | 56 | 18 | | public static string ToWireName(InsightsWindow window) => window switch |
| | 56 | 19 | | { |
| | 32 | 20 | | InsightsWindow.Last90Days => Last90DaysName, |
| | 24 | 21 | | InsightsWindow.AllTime => AllTimeName, |
| | 0 | 22 | | _ => throw new ArgumentOutOfRangeException(nameof(window), window, "Unknown Insights window.") |
| | 56 | 23 | | }; |
| | | 24 | | |
| | | 25 | | public static bool TryParse(string? value, out InsightsWindow window) |
| | | 26 | | { |
| | | 27 | | switch (value) |
| | | 28 | | { |
| | | 29 | | case Last90DaysName: |
| | 38 | 30 | | window = InsightsWindow.Last90Days; |
| | 38 | 31 | | return true; |
| | | 32 | | case AllTimeName: |
| | 20 | 33 | | window = InsightsWindow.AllTime; |
| | 20 | 34 | | return true; |
| | | 35 | | default: |
| | 20 | 36 | | window = default; |
| | 20 | 37 | | return false; |
| | | 38 | | } |
| | | 39 | | } |
| | | 40 | | } |