using DocuMed.Common.Models.Claims;

namespace DocuMed.PWA.Utilities;

public class UserUtility : IUserUtility
{
    private readonly ILocalStorageService _localStorageService;

    public UserUtility(ILocalStorageService localStorageService)
    {
        _localStorageService = localStorageService;
    }

    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);
}