using Microsoft.AspNetCore.Mvc;
using Nop.Web.Framework.Controllers;
using Nop.Web.Framework.Mvc.Filters;
using Nop.Web.Framework;
using Nop.Plugin.Misc.SignalRApi.Services;
using Nop.Plugin.Misc.SignalRApi.Models;

[AutoValidateAntiforgeryToken]
[AuthorizeAdmin]
[Area(AreaNames.ADMIN)]
public class SignalRApiAdminController : BasePluginController
{
    private readonly SignalRservice _signalRservice;

    public SignalRApiAdminController(SignalRservice signalRservice)
    {
        _signalRservice = signalRservice;
    }

    public async Task<IActionResult> Configure(bool showtour = false)
    {
        return View("~/Plugins/Misc.SignalRApi/Views/Configure.cshtml", new ConfigurationModel());
    }

    [HttpPost]
    public async Task<IActionResult> TestHubConnection(string message)
    {
        try
        {
            await _signalRservice.TestHub();
            return Json(new { success = true, message = $"Hub successfully called - {message}" });
        }
        catch (Exception ex)
        {
            return Json(new { success = false, message = $"Error: {ex.Message}" });
        }
    }
}
