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.Constants;
using PARR.DAL.Services.Interfaces;

namespace PARR.API.Controllers.V1
{
    /// <summary>
    /// Статусы ЭК
    /// </summary>
    [Authorize(Roles = ParrRoles.Administrator.Role)]
    public class EkStatusController : BaseApiController
    {
        private readonly IEkStatusService ekStatusService;
        private readonly IMapper mapper;

        public EkStatusController(
            IEkStatusService ekStatusService,
            IMapper mapper
            )
        {
            this.ekStatusService = ekStatusService;
            this.mapper = mapper;
        }


        /// <summary>
        /// Получить список статусов ЭК
        /// </summary>
        /// <returns></returns>млни
        [HttpGet(ApiRoutes.EkStatus.GetAll)]
        public async Task<IActionResult> GetAll()
        {
            var statuses = await ekStatusService.Get().OrderBy(t => t.Name).ToListAsync();

            if (!statuses.Any())
                return NoContent();

            var response = mapper.Map<List<EkStatusResponse>>(statuses);

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

    }
}
