using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;
using System.Collections.Generic;

using spanreed.Server.Data;

namespace spanreed.Server.Hubs {
    public class RoomHub : Hub {
        private readonly Rooms rooms;
        public RoomHub(Rooms rooms) {
            this.rooms = rooms;
        }

        public async Task Connect(string room) {
            await Groups.AddToGroupAsync(Context.ConnectionId, room);
        }

        public async Task AddRoom(string name) {
            if (!string.IsNullOrWhiteSpace(name) && !string.IsNullOrEmpty(name) && !rooms.RoomSet.Contains(name)) {
                rooms.RoomSet.Add(name);
                await Clients.All.SendAsync("NewRoom", name);
            }
        }
    }
}