using RudderSdk.Core;

namespace RudderSdk.Unity
{
  public static class RudderUnityClientFactory
  {
    public static RudderClient Create(RudderUnityClientOptions options)
    {
      var executor = options.RequestExecutor ?? new UnityWebRequestExecutor(options.TimeoutSeconds);

      var clientOptions = new RudderClientOptions
      {
        BaseUrl = options.BaseUrl,
        ProjectKey = options.ProjectKey,
        Logger = new UnityLoggerAdapter(options.LoggerSink ?? new UnityDebugLoggerSink()),
        Transport = new UnityTransportAdapter(options.BaseUrl, executor),
        TokenStore = new UnityTokenStoreAdapter(options.KeyValueStore),
        DeviceIdProvider = new UnityDeviceIdProvider(),
        Clock = new UnityClock()
      };

      return new RudderClient(clientOptions);
    }
  }
}
