using Managing.Domain.Shared.Helpers;
using Managing.Infrastructure.Evm.Services;
using Xunit;

namespace Managing.Infrastructure.Tests;

public class TradaoTests
{
    private readonly TradaoService _tradaoService;

    public TradaoTests()
    {
        _tradaoService = new TradaoService();
    }

    [Fact]
    public async void Should_return_best_trader()
    {
        var service = new TradaoService();
        var details = await service.GetBestTrader();
        Assert.NotNull(details);
    }

    [Fact]
    public async void Should_return_bad_trader()
    {
        var service = new TradaoService();
        var details = (await service.GetBadTrader()).FindBadTrader();
        Assert.NotNull(details);
    }

    [Fact]
    public async void Should_return_funding_rates()
    {
        var service = new TradaoService();
        var details = await service.GetFundingRates();
        Assert.NotNull(details);
    }

    [Fact]
    public void GetApy_WithPositiveRate_ReturnsExpectedPositiveApy()
    {
        var result = _tradaoService.GetApy("0.0055");
        Assert.True(result > 48m);
    }

    [Fact]
    public void GetApy_WithNegativeRate_ReturnsPositiveApy()
    {
        var result = _tradaoService.GetApy("-0.00834530");
        Assert.True(result < -73m);
    }

    [Fact]
    public void GetApy_WithZeroRate_ReturnsZeroApy()
    {
        var result = _tradaoService.GetApy("0");
        Assert.Equal(0m, result);
    }

    [Fact]
    public void GetApy_WithInvalidFormat_ThrowsFormatException()
    {
        Assert.Throws<FormatException>(() => _tradaoService.GetApy("invalid"));
    }
}