namespace MinicsConsole.Connector.Base;

public class SenderBase_SignalR
{
    public IHubCallerClients? Clients { get; set; }

    protected bool SendAll(string name)
    {
        if (Clients is null)
            return false;
        if (Clients.All is null)
            return false;

        try
        {
            Clients.All.SendAsync(name).Wait();
        }
        catch
        {
            return false;
        }

        return true;
    }

    protected bool SendAll<T>(string name, T para)
    {
        if (Clients is null)
            return false;
        if (Clients.All is null)
            return false;

        try
        {
            Clients.All.SendAsync(name, para).Wait();
        }
        catch
        {
            return false;
        }

        return true;
    }

    protected bool SendAll<T1, T2>(string name, T1 para1, T2 para2)
    {
        if (Clients is null)
            return false;
        if (Clients.All is null)
            return false;

        try
        {
            Clients.All.SendAsync(name, para1, para2).Wait();
        }
        catch
        {
            return false;
        }

        return true;
    }

    protected bool SendAll<T1, T2, T3>(string name, T1 para1, T2 para2, T3 para3)
    {
        if (Clients is null)
            return false;
        if (Clients.All is null)
            return false;

        try
        {
            Clients.All.SendAsync(name, para1, para2, para3).Wait();
        }
        catch
        {
            return false;
        }

        return true;
    }

    public bool SendCaller(string name)
    {
        if (Clients is null)
            return false;
        if (Clients.Caller is null)
            return false;

        try
        {
            Clients.Caller.SendAsync(name).Wait();
        }
        catch
        {
            return false;
        }

        return true;
    }

    public bool SendCaller<T>(string name, T para)
    {
        if (Clients is null)
            return false;
        if (Clients.Caller is null)
            return false;

        try
        {
            Clients.Caller.SendAsync(name, para).Wait();
        }
        catch
        {
            return false;
        }

        return true;
    }

    public bool SendCaller<T1, T2>(string name, T1 para1, T2 para2)
    {
        if (Clients is null)
            return false;
        if (Clients.Caller is null)
            return false;

        try
        {
            Clients.Caller.SendAsync(name, para1, para2).Wait();
        }
        catch
        {
            return false;
        }

        return true;
    }

    public bool SendCaller<T1, T2, T3>(string name, T1 para1, T2 para2, T3 para3)
    {
        if (Clients is null)
            return false;
        if (Clients.Caller is null)
            return false;

        try
        {
            Clients.Caller.SendAsync(name, para1, para2, para3).Wait();
        }
        catch
        {
            return false;
        }

        return true;
    }
}