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

namespace NetworkResurrector.Api.Controllers
{
    [Authorize(Policy = Policies.OperateMachines)]
    [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);
        }

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

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

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

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

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