using Microsoft.Extensions.Configuration;
using RestSharp;

namespace LazyBear.MCP.Services.GitLab;

/// <summary>
/// Фабрика клиента RestSharp для GitLab API
/// </summary>
public static class GitLabClientFactory
{
    private static readonly TimeSpan[] BackoffDurations =
    {
        TimeSpan.FromMilliseconds(1000),
        TimeSpan.FromMilliseconds(2000),
        TimeSpan.FromMilliseconds(4000)
    };

    /// <summary>
    /// Создание клиента RestSharp для GitLab API
    /// </summary>
    /// <param name="configuration">Конфигурация из DI</param>
    /// <returns>Client или null при ошибке инициализации</returns>
    public static RestClient? CreateClient(IConfiguration configuration)
    {
        var gitlabUrl = configuration["GitLab:Url"] ?? string.Empty;

        if (string.IsNullOrWhiteSpace(gitlabUrl))
        {
            return null;
        }

        var config = new RestClientOptions(gitlabUrl)
        {
            UserAgent = "LazyBear-GitLab-MCP",
            Timeout = TimeSpan.FromMilliseconds(30000)
        };

        return new RestClient(config);
    }
}