using DocuMed.Common.Models.Claims;

namespace DocuMed.PWA.Utilities;

public class UserUtility(ILocalStorageService localStorageService) : IUserUtility
{
    public async Task<string> GetBearerTokenAsync() => await localStorageService.GetItemAsStringAsync(LocalStorageKeys.Token);
    public async Task SetBearerTokenAsync(string token) => await localStorageService.SetItemAsStringAsync(LocalStorageKeys.Token, token);

    public async Task<ApplicationUserSDto> GetUserAsync() => await localStorageService.GetItemAsync<ApplicationUserSDto>(LocalStorageKeys.UserInfo);
    public async Task SetUserAsync(ApplicationUserSDto user) => await localStorageService.SetItemAsync<ApplicationUserSDto>(LocalStorageKeys.UserInfo, user);
    public async Task LogoutAsync()
    {
        await localStorageService.RemoveItemAsync(LocalStorageKeys.Token);
        await localStorageService.RemoveItemAsync(LocalStorageKeys.UserInfo);
    }

    //public AccessToken<ApplicationUserSDto>? AccessToken { get; set; }
    //public List<string> UserClaims => AccessToken == null ? new List<string>() : AccessToken.Permissions;
    //public bool HasPermissionTo(string permission) => UserClaims.Any(c => c == permission);
}