using AyCode.Interfaces.StorageHandlers;
using Blazored.LocalStorage;
using TIAMWebApp.Shared.Application.Interfaces;

namespace TIAMWebApp.Client.Services
{
    public class SecureStorageHandler : ISecureStorageHandler
    {
        private readonly SessionStorageAccessor ssa;
        private readonly ILocalStorageService localStoragService;

        public SecureStorageHandler(SessionStorageAccessor ssa, ILocalStorageService localStorageService)
        {
            this.ssa = ssa;
            this.localStoragService = localStorageService;
        }


        public async Task SaveToSecureStorageAsync(string key, string value)
        {
            await localStoragService.SetItemAsync(key, value);
            //await ssa.SetValueAsync(key, value);


        }

        public async Task<string> GetFromSecureStorageAsync(string key)
        {
            return await localStoragService.GetItemAsync<string>(key);
            //return await ssa.GetValueAsync<string>(key);

        }

        public async Task DeleteFromSecureStorageAsync(string key)
        {
            await localStoragService.RemoveItemAsync(key);
            //await ssa.RemoveAsync(key);
        }

        public async Task ClearAllSecureStorageAsync()
        {
            await localStoragService.ClearAsync();
            //await ssa.Clear();
        }
    }
}
