using Device;
using EEMSClientCore;
using EEMSUIClientCore;
using ServiceBase;

namespace TestSignalRClient;

internal class Program
{
    static void Main(string[] args)
    {
        UITest test = new();
        test.Test();

        Thread.Sleep(-1);
    }
}

internal class UITest : IUIProvider
{

    public void Test()
    {
        HubBase hubBase = new();
        hubBase.Initialize(this);
        bool b = hubBase.Open("127.0.0.1", 50054, "UIHub");
        Console.WriteLine($"Open UI Client {b}");
    }

    public Task<bool> InsertNewDevice(DeviceInfo deviceInfo)
    {
        Console.WriteLine($"InsertNewDevice {deviceInfo.DeviceName} {deviceInfo.Guid}");
        return Task.FromResult(true);
    }
    public Task<bool> UpdateDevice(DeviceInfo device)
    {
        Console.WriteLine($"UpdateDevice {device.DeviceName} {device.Guid}");
        return Task.FromResult(true);
    }

    public Task<bool> UpdateDeviceList(IEnumerable<DeviceInfo> device)
    {
        foreach (var deviceInfo in device)
        {
            Console.WriteLine($"UpdateDeviceList {deviceInfo.DeviceName} {deviceInfo.Guid}");
        }
        return Task.FromResult(true);
    }

    public Task<bool> UpdateRealtimeData(Guid guid, Dictionary<string, object> data)
    {
        Console.WriteLine($"UpdateRealtimeData {guid} {data.Count}");
        foreach (var item in data)
        {
            Console.WriteLine($"UpdateRealtimeData {item.Key} {item.Value}");
        }
        return Task.FromResult(true);
    }

    public Task<bool> OnlineStatusNotify(Guid guid, bool onlineStatus)
    {
        Console.WriteLine($"OnlineStatusNotify {guid} {onlineStatus}");
        return Task.FromResult(true);
    }

    Task<bool> IUIProvider.UpdateDeviceList(IEnumerable<DeviceInfo> device)
    {
        return Task.FromResult(true);

    }

    Task<bool> IUIProvider.UpdateDevice(DeviceInfo device)
    {
        return Task.FromResult(true);

    }

    Task<bool> IUIProvider.InsertNewDevice(DeviceInfo deviceInfo)
    {
        return Task.FromResult(true);
    }

    Task<bool> IUIProvider.UpdateRealtimeData(Guid guid, Dictionary<string, object> data)
    {
        return Task.FromResult(true);
    }

    Task<bool> IUIProvider.UpdateAlarm(IEnumerable<Alarm> alarm)
    {
        return Task.FromResult(true);
    }

    Task<bool> IUIProvider.UpdateRecipeInfo(Recipe recipeInfo)
    {
        return Task.FromResult(true);
    }
}

internal class ClientTest
{
    public void Test()
    {
        IClientBaseProvider baseProvider = new ClientBaseProvider();
        ClientCaller hubSender = new(baseProvider);
        IClientCaller caller = hubSender;
        hubSender.Initialize();
        hubSender.Open("localhost", 50054, "ClientHub");

        DeviceInfo deviceInfo = new()
        {

        };

        Guid guid = caller.RegisterDevice(deviceInfo).Result;
        Console.WriteLine(guid);
    }
}

internal class ClientBaseProvider : IClientBaseProvider
{
    public string? RecipePath { get; set; }
    public string? ConfigPath { get; set; }
    string? IClientBaseProvider.RecipePath { get; set; }
    string? IClientBaseProvider.ConfigPath { get; set; }

    bool IClientBaseProvider.AllowReceiveFile()
    {
        return true;
    }

    void IClientBaseProvider.FileReceivedNotify(FileType fileType, string path)
    {
    }

    void IClientBaseProvider.StartFileReceiveNotify(FileType fileType)
    {
    }

    void IClientBaseProvider.UpdateDeviceInfo(DeviceInfo deviceInfo)
    {
    }
}