using Blazored.LocalStorage;
using System.Runtime.CompilerServices;

namespace FNZCM.BlazorWasm.Helpers
{
    public class LocalStorageHelper
    {
        private readonly ISyncLocalStorageService localStorage;

        public LocalStorageHelper(ISyncLocalStorageService localStorage) => this.localStorage = localStorage;
        public void Clear() => localStorage.Clear();

        public void SetByCallerMemberName<T>(T value, [CallerMemberName] string key = null) => localStorage.SetItem(key, value);
        public T GetByCallerMemberName<T>([CallerMemberName] string key = null) => localStorage.GetItem<T>(key);
        public void RemoveByCallerMemberName([CallerMemberName] string key = null) => localStorage.RemoveItem(key);

        public void Set<T>(string key, T value) => localStorage.SetItem(key, value);
        public T Get<T>(string key) => localStorage.GetItem<T>(key);
        public void Remove(string key) => localStorage.RemoveItem(key);
    }
}
