using ClaudeDo.Worker.Hub;
using Microsoft.AspNetCore.SignalR;

namespace ClaudeDo.Worker.Tests.Infrastructure;

public sealed record CapturedHubCall(string Method, object?[] Args);

public sealed class CapturingClientProxy : IClientProxy
{
    public readonly List<CapturedHubCall> Calls = new();

    public Task SendCoreAsync(string method, object?[] args, CancellationToken cancellationToken = default)
    {
        Calls.Add(new CapturedHubCall(method, args));
        return Task.CompletedTask;
    }
}

public sealed class CapturingHubClients : IHubClients
{
    public CapturingClientProxy AllProxy { get; } = new();
    public IClientProxy All => AllProxy;
    public IClientProxy AllExcept(IReadOnlyList<string> excludedConnectionIds) => AllProxy;
    public IClientProxy Client(string connectionId) => AllProxy;
    public IClientProxy Clients(IReadOnlyList<string> connectionIds) => AllProxy;
    public IClientProxy Group(string groupName) => AllProxy;
    public IClientProxy GroupExcept(string groupName, IReadOnlyList<string> excludedConnectionIds) => AllProxy;
    public IClientProxy Groups(IReadOnlyList<string> groupNames) => AllProxy;
    public IClientProxy User(string userId) => AllProxy;
    public IClientProxy Users(IReadOnlyList<string> userIds) => AllProxy;
}

public sealed class CapturingHubContext : IHubContext<WorkerHub>
{
    private readonly CapturingHubClients _clients = new();
    public CapturingClientProxy Proxy => _clients.AllProxy;
    public IHubClients Clients => _clients;
    public IGroupManager Groups => throw new NotImplementedException();
}
