using MongoDB.Driver;
namespace Core.Blueprint.Mongo
{
    /// 
    /// Provides the MongoDB provider and database connection using the specified configuration settings.
    /// This class manages the connection to MongoDB and ensures that the correct credentials are used for authentication.
    /// 
    public class MongoProvider
    {
        private readonly IMongoDatabase _database;
        /// 
        /// Initializes a new instance of the  class.
        /// This constructor sets up the MongoDB provider using the connection string, audience, and other settings provided.
        /// It also configures authentication using OpenID Connect (OIDC) credentials.
        /// 
        /// The MongoDB settings required for connecting to the database.
        public MongoProvider(IMongoDatabase database)
        {
            _database = database ?? throw new ArgumentNullException(nameof(database));
        }
        /// 
        /// Gets the initialized MongoDB database. If the database is not initialized, an exception is thrown.
        /// 
        /// Thrown when the database connection is not initialized.
        protected IMongoDatabase Database
        {
            get
            {
                if (_database == null)
                {
                    throw new InvalidOperationException("MongoDB connection is not initialized.");
                }
                return _database;
            }
        }
    }
}