using Diligent.WebAPI.Data;
using Microsoft.Extensions.Options;
using MongoDB.Driver;

namespace Diligent.WebAPI.Business.MongoServices
{
    public class BaseMongo<T> where T : class
    {
        protected readonly IMongoCollection<T> _mongoCollection;
        private readonly MongoClient _mongoClient;
        private readonly IMongoDatabase _mongoDatabase;
        public BaseMongo(IOptions<WebApiDatabaseSettings> webApiDatabaseSettings,string nameOfCollection)
        {
           _mongoClient = new MongoClient(
               webApiDatabaseSettings.Value.ConnectionString);

           _mongoDatabase = _mongoClient.GetDatabase(
                webApiDatabaseSettings.Value.DatabaseName);

            _mongoCollection = _mongoDatabase.GetCollection<T>(nameOfCollection);
        }
    }
}
