using Microsoft.Extensions.Configuration;
using Xunit;

namespace ZB.MOM.WW.LmxProxy.Client.Tests;

public class LmxProxyClientFactoryTests
{
    [Fact]
    public void CreateClient_BindsFromConfiguration()
    {
        var config = new ConfigurationBuilder()
            .AddInMemoryCollection(new Dictionary<string, string?>
            {
                ["LmxProxy:Host"] = "10.100.0.48",
                ["LmxProxy:Port"] = "50052",
                ["LmxProxy:ApiKey"] = "test-key",
                ["LmxProxy:Retry:MaxAttempts"] = "5",
                ["LmxProxy:Retry:Delay"] = "00:00:02",
            })
            .Build();

        var factory = new LmxProxyClientFactory(config);
        var client = factory.CreateClient();
        Assert.NotNull(client);
    }

    [Fact]
    public void CreateClient_NamedSection()
    {
        var config = new ConfigurationBuilder()
            .AddInMemoryCollection(new Dictionary<string, string?>
            {
                ["MyProxy:Host"] = "10.100.0.48",
                ["MyProxy:Port"] = "50052",
            })
            .Build();

        var factory = new LmxProxyClientFactory(config);
        var client = factory.CreateClient("MyProxy");
        Assert.NotNull(client);
    }

    [Fact]
    public void CreateClient_BuilderAction()
    {
        var config = new ConfigurationBuilder().Build();
        var factory = new LmxProxyClientFactory(config);
        var client = factory.CreateClient(b => b.WithHost("localhost").WithPort(50051));
        Assert.NotNull(client);
    }
}
