using GameIdeas.Shared.Dto; using Microsoft.AspNetCore.Components.Authorization; using System.Security.Claims; namespace GameIdeas.BlazorApp.Helpers; public static class GameHelper { public static void WriteTrackingDto(GameDetailDto game, AuthenticationState authState) { if (authState == null) { throw new ArgumentNullException(nameof(authState), "Authentication state missing"); } var userId = authState.User.FindFirstValue(ClaimTypes.Sid); if (userId == null) { throw new ArgumentNullException(nameof(authState), "user state missing"); } game.CreationUserId = userId; game.CreationDate = DateTime.Now; } public static string GetInterestColor(int interest, int maxInterest) { int firstTier = (int)Math.Floor(0.33 * maxInterest); int secondTier = (int)Math.Ceiling(0.66 * maxInterest); return interest switch { int x when x <= firstTier => "--red", int x when x >= secondTier => "--green", _ => "--yellow", }; } public static string GetFormatedStorageSpace(double? storageValue) { if (storageValue == null) { return string.Empty; } return storageValue switch { >= 1000000 => $"{storageValue / 1000000:f1} To", >= 1000 => $"{storageValue / 1000:f1} Go", _ => $"{storageValue:f1} Mo" }; } }