using MarcoBMS.Services.Service;
using Microsoft.AspNetCore.SignalR;

namespace Marco.Pms.Services.Hubs
{
    public class MarcoHub : Hub
    {
        private readonly ILoggingService _logger;
        public MarcoHub(ILoggingService logger)
        {
            _logger = logger;
        }
        public async Task SendMessage(string user, string message)
        {
            _logger.LogInfo($"User: {user} Message : {message}");
            await Clients.All.SendAsync("ReceiveMessage", user, message);
        }
        public override async Task OnConnectedAsync()
        {
            await base.OnConnectedAsync();
            _logger.LogInfo($"Connected successfully");
            await Clients.All.SendAsync("Connected successfully");
        }

        // Optional: override OnDisconnectedAsync
        public override async Task OnDisconnectedAsync(Exception? exception)
        {
            await base.OnDisconnectedAsync(exception);
            _logger.LogInfo($"DIsonnected successfully");
            await Clients.All.SendAsync("Disonnected successfully");
        }
    }
}
