using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using PARR.API.Contracts.V1;
using PARR.API.Contracts.V1.Responses;
using PARR.API.Contracts.V1.Responses.Base;
using PARR.API.Controllers.V1.Base;
using PARR.Core.Services.TaskServices.Interfaces;
using PARR.Domain.Common.Roles;
using PARR.Domain.Enums;

namespace PARR.API.Controllers.V1
{
    /// <summary>
    /// Контроллер по управлению Task (задания, очереди)
    /// </summary>
    [Authorize(Roles = ParrRoles.Administrator.Role)]
    public class TaskController : BaseApiController
    {
        private readonly ITaskManagementService taskManagementService;
        private readonly IMapper mapper;

        public TaskController(
                ITaskManagementService taskManagementService,
                IMapper mapper
            )
        {
            this.taskManagementService = taskManagementService;
            this.mapper = mapper;
        }


        /// <summary>
        /// Получить список активных задач (задания, очереди)
        /// </summary>
        /// <returns></returns>
        [HttpGet(ApiRoutes.Tasks.GetActiveTasks)]
        public async Task<IActionResult> GetActiveTasks([FromQuery] TaskTypeEnum? typeCode)
        {
            var activeTasks = await taskManagementService.GetActiveTasksAsync(typeCode);

            if (activeTasks.Count == 0)
                return NoContent();

            var response = mapper.Map<List<ActiveTaskResponse>>(activeTasks);

            return Ok(new Response<List<ActiveTaskResponse>>(response, true));
        }

    }
}
