using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NetworkResurrector.Api.Application.Queries;
using NetworkResurrector.Api.Authorization.Constants;
using System.Threading.Tasks;

namespace NetworkResurrector.Api.Controllers
{
    [ApiController]
    [Authorize]
    [Route("network")]
    public class NetworkController : ControllerBase
    {
        private readonly IMediator _mediator;

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

        [HttpGet("machines")]
        [Authorize(Policy = Policies.ViewMachines)]
        public async Task<IActionResult> GetMachines([FromRoute] GetMachines.Query query)
        {
            var result = await _mediator.Send(query);
            return Ok(result);
        }
    }
}
