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,
        RealtimeUrl = options.RealtimeUrl,
        ProjectKey = options.ProjectKey,
        Logger = new UnityLoggerAdapter(options.LoggerSink ?? new UnityDebugLoggerSink()),
        Transport = new UnityTransportAdapter(options.BaseUrl, executor),
        UploadTransport = new UnityUploadTransport(options.TimeoutSeconds),
        TokenStore = new UnityTokenStoreAdapter(options.KeyValueStore),
        DeviceIdProvider = new UnityDeviceIdProvider(),
        Clock = new UnityClock(),
        PlanStateStore = new UnityPlanStateStore(options.KeyValueStore),
        Scheduler = new UnityPlanScheduler(),
        RealtimeTransportFactory = new UnityRealtimeTransportFactory()
      };

      return new RudderClient(clientOptions);
    }
  }
}
