

namespace EEMSServerCore.HubSender;

internal class UICaller : IUIProvider
{
    public Task<bool> UpdateDevice(DeviceInfo device)
    {
        throw new NotImplementedException();
    }

    public Task<bool> UpdateDeviceList(IEnumerable<DeviceInfo> device)
    {
        throw new NotImplementedException();
    }

    private Task<bool> SendAsync(string name)
    {
        if (string.IsNullOrEmpty(name))
            return Task.FromResult(false);

        if (ClientManager.UIClient is null)
            return Task.FromResult(false);

        try
        {
            ClientManager.UIClient.SendAsync("test");
        }
        catch
        {
            return Task.FromResult(false);
        }
        return Task.FromResult(true);
    }

    private Task<bool> SendAsync<T>(string name, T para)
    {
        if (string.IsNullOrEmpty(name))
            return Task.FromResult(false);

        if (ClientManager.UIClient is null)
            return Task.FromResult(false);

        try
        {
            ClientManager.UIClient.SendAsync(name, para);
        }
        catch
        {
            return Task.FromResult(false);
        }
        return Task.FromResult(true);
    }

    private Task<bool> SendAsync<T1, T2>(string name, T1 para1, T2 para2)
    {
        if (string.IsNullOrEmpty(name))
            return Task.FromResult(false);

        if (ClientManager.UIClient is null)
            return Task.FromResult(false);

        try
        {
            ClientManager.UIClient.SendAsync(name, para1, para2);
        }
        catch
        {
            return Task.FromResult(false);
        }
        return Task.FromResult(true);
    }

    private Task<bool> SendAsync<T1, T2, T3>(string name, T1 para1, T2 para2, T3 para3)
    {
        if (string.IsNullOrEmpty(name))
            return Task.FromResult(false);

        if (ClientManager.UIClient is null)
            return Task.FromResult(false);

        try
        {
            ClientManager.UIClient.SendAsync(name, para1, para2, para3);
        }
        catch
        {
            return Task.FromResult(false);
        }
        return Task.FromResult(true);
    }

    private Task<bool> SendAsync<T1, T2, T3, T4>(string name, T1 para1, T2 para2, T3 para3, T4 para4)
    {
        if (string.IsNullOrEmpty(name))
            return Task.FromResult(false);

        if (ClientManager.UIClient is null)
            return Task.FromResult(false);

        try
        {
            ClientManager.UIClient.SendAsync(name, para1, para2, para3, para4);
        }
        catch
        {
            return Task.FromResult(false);
        }
        return Task.FromResult(true);
    }

}