using Microsoft.Extensions.DependencyInjection;

using MongoDB.Driver;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.IdGenerators;

using DataProviders.Collections;
using DataProviders.Buckets;

namespace DataProviders.Extensions
{
  public static class ServiceCollectionExtensions {
    public static void RegisterDataproviders(this IServiceCollection services, IDataProvidersConfig appSettings) {
      var config = appSettings.Database;

      services.AddSingleton<IMongoClient>(x => new MongoClient(config.ConnectionString));
      services.AddSingleton<IIdGenerator, GuidGenerator>();

      Mappings.RegisterClassMap();

      services.AddSingleton<ISessionService, SessionService>();

      #region Collections
      services.AddSingleton<IContentDataProvider, ContentDataProvider>();
      services.AddSingleton<IShopCatalogDataProvider, ShopCatalogDataProvider>();
      services.AddSingleton<IShopCartDataProvider, ShopCartDataProvider>();
      services.AddSingleton<ICategoryDataProvider, CategoryDataProvider>();
      services.AddSingleton<IBlogCatalogDataProvider, BlogCatalogDataProvider>();
      services.AddSingleton<IUserDataProvider, UserDataProvider>();
      #endregion

      #region Buckets
      services.AddSingleton<IImageBucketDataProvider, ImageBucketDataProvider>();
      #endregion
    }
  }
}
