using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
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.Repositories.Interfaces;
using PARR.Domain.Common.Roles;

namespace PARR.API.Controllers.V1
{
    /// <summary>
    /// Статусы заданий роботам
    /// </summary>
    [Authorize(Roles = ParrRoles.EsppRobot.RoleOrAdmin)]
    public class TaskStatusController : BaseApiController
    {
        private readonly IMapper mapper;
        private readonly IStatusTemplateRepository statusTemplateService;

        public TaskStatusController(
            IMapper mapper,
            IStatusTemplateRepository statusTemplateService
            )
        {
            this.mapper = mapper;
            this.statusTemplateService = statusTemplateService;
        }

        /// <summary>
        /// Получить список статусов заданий роботам
        /// </summary>
        /// <returns></returns>
        [HttpGet(ApiRoutes.TaskStatus.GetAll)]
        public async Task<IActionResult> GetAll()
        {
            var statusList = await statusTemplateService.Get()
                .OrderBy(t => t.Code)
                .ToListAsync();

            var response = mapper.Map<List<TaskStatusResponse>>(statusList);

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