using System;
using System.Collections.Generic;
using System.Linq;
using InABox.Client.WebSocket;

namespace InABox.Clients
{
    public static class SocketClientCache
    {
        private static Dictionary<string, WebSocketClient> Clients = new Dictionary<string, WebSocketClient>();

        public static void StartWebSocket(string url, int port, Guid session)
        {
            var host = url.Split(new[] { "://" }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();

            Uri uri = new Uri($"http://{host}");
            var key = $"{uri.Host}:{uri.Port}${session}";
            if (!Clients.ContainsKey(key))
                Clients[key] = new WebSocketClient(uri.Host, port, session);
        }
    }
}