using ClaudeDo.Data.Models;
using ClaudeDo.Worker.External;
using ClaudeDo.Worker.Tests.Infrastructure;
using Microsoft.EntityFrameworkCore;

namespace ClaudeDo.Worker.Tests.External;

public sealed class AppSettingsMcpToolsTests : IDisposable
{
    private readonly DbFixture _db = new();

    public void Dispose() => _db.Dispose();

    [Fact]
    public async Task GetAppSettings_ReturnsMaxParallelExecutionsFromDb()
    {
        using (var ctx = _db.CreateContext())
        {
            var row = await ctx.AppSettings.FirstOrDefaultAsync(s => s.Id == AppSettingsEntity.SingletonId)
                ?? throw new InvalidOperationException("Expected seeded app_settings row.");
            row.MaxParallelExecutions = 3;
            await ctx.SaveChangesAsync();
        }

        var sut = new AppSettingsMcpTools(_db.CreateFactory());

        var result = await sut.GetAppSettings(CancellationToken.None);

        Assert.Equal(3, result.MaxParallelExecutions);
    }
}
