namespace IamService.Infrastructure.Caching;

/// <summary>
/// EN: Redis configuration settings
/// VI: Cấu hình Redis settings
/// </summary>
public class RedisSettings
{
    public const string SectionName = "Redis";
    
    public string Host { get; set; } = "localhost";
    public int Port { get; set; } = 6379;
    public string? Password { get; set; }
    public int Database { get; set; } = 0;
    public int ConnectTimeout { get; set; } = 5000;
    public int SyncTimeout { get; set; } = 5000;
    
    /// <summary>
    /// EN: Get the connection string for StackExchange.Redis
    /// VI: Lấy connection string cho StackExchange.Redis
    /// </summary>
    public string GetConnectionString()
    {
        var config = $"{Host}:{Port}";
        
        if (!string.IsNullOrEmpty(Password))
        {
            config += $",password={Password}";
        }
        
        config += $",defaultDatabase={Database}";
        config += $",connectTimeout={ConnectTimeout}";
        config += $",syncTimeout={SyncTimeout}";
        config += ",abortConnect=false";
        
        return config;
    }
}
