using ClaudeDo.Ui.Services;
using ClaudeDo.Ui.ViewModels.Modals;

namespace ClaudeDo.Ui.Tests;

public sealed class RepoImportCandidatesTests
{
    [Fact]
    public void BuildCandidates_NewRepo_IsUncheckedAndNotAlreadyAdded()
    {
        var found = new[] { new RepoCandidate("repo-a", @"C:\src\repo-a") };
        var current = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
        var existing = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

        var items = RepoImportModalViewModel.BuildCandidates(found, current, existing);

        Assert.Single(items);
        Assert.False(items[0].IsChecked); // new repos are not auto-selected
        Assert.False(items[0].AlreadyAdded);
        Assert.Equal("repo-a", items[0].Name);
        Assert.Equal(@"C:\src\repo-a", items[0].FullPath);
    }

    [Fact]
    public void BuildCandidates_ExistingWorkingDir_IsMarkedAlreadyAdded()
    {
        var found = new[] { new RepoCandidate("repo-a", @"C:\src\repo-a") };
        var current = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
        var existing = new HashSet<string>(new[] { @"c:\src\repo-a" }, StringComparer.OrdinalIgnoreCase);

        var items = RepoImportModalViewModel.BuildCandidates(found, current, existing);

        Assert.Single(items);
        Assert.True(items[0].AlreadyAdded);
        Assert.True(items[0].IsChecked); // already-added rows render ticked
    }

    [Fact]
    public void BuildCandidates_SkipsPathsAlreadyShown()
    {
        var found = new[] { new RepoCandidate("repo-a", @"C:\src\repo-a") };
        var current = new HashSet<string>(new[] { @"c:\src\repo-a" }, StringComparer.OrdinalIgnoreCase);
        var existing = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

        var items = RepoImportModalViewModel.BuildCandidates(found, current, existing);

        Assert.Empty(items);
    }
}
