using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NetworkResurrector.Server.PublishedLanguage.Commands;
using System.Threading.Tasks;

namespace NetworkResurrector.Server.Controllers
{
    [Authorize]
    [ApiController]
    [Route("resurrector")]
    public class ResurrectorController : ControllerBase
    {
        private readonly IMediator _mediator;

        public ResurrectorController(IMediator mediator)
        {
            _mediator = mediator;
        }

        [HttpPost("wake")]
        public async Task<IActionResult> WakeMachine([FromBody] WakeMachine wakeMachine)
        {
            var result = await _mediator.Send(wakeMachine);
            return Ok(result);
        }

        [HttpPost("ping")]
        public async Task<IActionResult> PingMachine([FromBody] PingMachine pingMachine)
        {
            var result = await _mediator.Send(pingMachine);
            return Ok(result);
        }

        [HttpPost("shutdown")]
        public async Task<IActionResult> ShutdownMachine([FromBody] ShutdownMachine shutdownMachine)
        {
            var result = await _mediator.Send(shutdownMachine);
            return Ok(result);
        }
    }
}
