using RudderSdk.Core.Abstractions;

namespace RudderSdk.Unity
{
  internal class UnityTokenStoreAdapter : ITokenStore
  {
    private readonly IUnityKeyValueStore _store;

    public UnityTokenStoreAdapter(IUnityKeyValueStore store) => _store = store;

    public string GetAccessToken() => _store.GetString("liveops_access_token");
    public string GetRefreshToken() => _store.GetString("liveops_refresh_token");

    public void SaveTokens(string accessToken, string refreshToken)
    {
      _store.SetString("liveops_access_token", accessToken);
      _store.SetString("liveops_refresh_token", refreshToken);
      _store.Save();
    }

    public void Clear()
    {
      _store.DeleteKey("liveops_access_token");
      _store.DeleteKey("liveops_refresh_token");
      _store.Save();
    }
  }
}
