using MongoDB.Driver;

namespace Diligent.WebAPI.Data
{
    public class MongoDBContext : IMongoDBContext
    {
        private readonly IConfiguration _configuration;

        private IMongoDatabase _db { get; set; }
        private MongoClient _mongoClient { get; set; }
        public IClientSessionHandle Session { get; set; }
        public MongoDBContext(IConfiguration configuration)
        {
            _configuration = configuration;
            var mongoDbSettings = _configuration.GetSection("WebApiDB");
            _mongoClient = new MongoClient(mongoDbSettings["ConnectionString"]);
            _db = _mongoClient.GetDatabase(mongoDbSettings["DatabaseName"]);
        }

        public IMongoCollection<Request> GetCollection<Request>(string id)
        {
            return _db.GetCollection<Request>(id);
        }
    }
}
