using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Aurora.Core.IService;
using Aurora.Core.IService.Dto;
using Aurora.Infrastructure.Response;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;

namespace Aurora.Core.Api.Controllers
{
    [ApiController]
    [Route("[controller]/[action]")]
    public class TranslateController : ControllerBase
    {
        private readonly ILogger<TranslateController> _logger;
        private readonly IRocketService _rocketService;
        private readonly IHubContext<TranslateRocketHub> _hubContext;

        public TranslateController(ILogger<TranslateController> logger,
        IRocketService rocketService,
         IHubContext<TranslateRocketHub> hubContext)
        {
            _logger = logger;
            _rocketService = rocketService;
            _hubContext = hubContext;
        }

        [HttpGet]
        /// <summary>
        /// get words list
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> GetList()
        {
            var res = await _rocketService.GetList();
            return Ok(res);
        }

        [HttpPost]
        /// <summary>
        /// biu word
        /// </summary>
        /// <returns></returns>
        public async Task<ActionResult> Rocket(RocketWordDto model)
        {
            // var res = await _rocketService.Rocket(model);

            await _hubContext.Clients.All.SendAsync("rocketWord", model);
            return Ok("Echo:" + model.Text); //res;
        }

        [HttpGet]
        /// <summary>
        /// biu word
        /// </summary>
        /// <returns></returns>
        public async Task<ResponseModel<RocketWordDto>> Test()
        {
            await _hubContext.Clients.All.SendAsync("rocketWord", "model");
            return new ResponseModel<RocketWordDto>(new RocketWordDto());
        }
    }
}
