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
{
    [Authorize(Roles = ParrRoles.EsppRobot.RoleOrAdmin)]
    public class RobotHistoryLevelController : BaseApiController
    {
        private readonly IMapper mapper;
        private readonly IRobotHistoryLevelRepository robotHistoryLevelService;

        public RobotHistoryLevelController(
                IMapper mapper,
                IRobotHistoryLevelRepository robotHistoryLevelService
            )
        {
            this.mapper = mapper;
            this.robotHistoryLevelService = robotHistoryLevelService;
        }

        /// <summary>
        /// Получить список уровней истории работы робота
        /// </summary>
        /// <returns></returns>
        [HttpGet(ApiRoutes.RobotHistoryLevel.GetAll)]
        public async Task<IActionResult> GetAll()
        {
            var levels = await robotHistoryLevelService.Get()
                                .OrderBy(t => t.Level)
                                .ToListAsync();

            var response = mapper.Map<List<RobotHistoryLevelResponse>>(levels);

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