using Microsoft.Extensions.Configuration;
namespace Core.Blueprint.Mongo
{
    /// 
    /// The  class represents the MongoDB context that contains the connection information, 
    /// including the connection string, database name, and audience.
    /// It implements the  interface to provide methods for accessing these values.
    /// 
    public sealed class MongoContext : IMongoContext
    {
        /// 
        /// Gets or sets the connection string used to connect to the MongoDB instance.
        /// 
        public string ConnectionString { get; set; } = string.Empty;
        /// 
        /// Gets or sets the name of the MongoDB database.
        /// 
        public string Databasename { get; set; } = string.Empty;
        /// 
        /// Gets or sets the audience (resource identifier) used for MongoDB authentication.
        /// 
        public string Audience { get; set; } = string.Empty;
        private readonly IConfiguration configuration;
        /// 
        /// Initializes a new instance of the  class using the provided .
        /// The configuration is used to retrieve MongoDB connection settings.
        /// 
        /// The configuration used to retrieve the MongoDB connection settings.
        public MongoContext(IConfiguration configuration)
        {
            this.configuration = configuration;
        }
        /// 
        /// Retrieves the MongoDB connection string from the configuration.
        /// 
        /// The MongoDB connection string, or an empty string if not found.
        public string GetConnectionString()
        {
            return configuration.GetConnectionString("MongoDb:ConnectionString")?.ToString() ?? string.Empty;
        }
        /// 
        /// Retrieves the MongoDB database name from the configuration.
        /// 
        /// The MongoDB database name, or an empty string if not found.
        public string GetDatabasename()
        {
            return configuration.GetSection("MongoDb:DatabaseName").Value ?? string.Empty;
        }
        /// 
        /// Retrieves the MongoDB audience (resource identifier) from the configuration.
        /// 
        /// The MongoDB audience, or an empty string if not found.
        public string GetAudience()
        {
            return configuration.GetSection("MongoDb:Audience").Value ?? string.Empty;
        }
    }
}