using Microsoft.Extensions.Configuration;
using RestSharp;

namespace LazyBear.MCP.Services.Jira;

public static class JiraClientFactory
{
    private static readonly TimeSpan[] BackoffDurations = {
        TimeSpan.FromMilliseconds(1000),
        TimeSpan.FromMilliseconds(2000),
        TimeSpan.FromMilliseconds(4000)
    };

    public static RestClient CreateClient(IConfiguration configuration)
    {
        var jiraUrl = configuration["Jira:Url"] ?? "";

        if (string.IsNullOrWhiteSpace(jiraUrl))
        {
            throw new Exception("Jira:Url не задан");
        }

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

        return new RestClient(config);
    }
}
