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.Administrator.Role)]
    public class TemplateStatusTypeController : BaseApiController
    {
        private readonly IMapper mapper;
        private readonly ITemplateStatusTypeRepository templateStatusTypeService;

        public TemplateStatusTypeController(
            IMapper mapper,
            ITemplateStatusTypeRepository templateStatusTypeService
            )
        {
            this.mapper = mapper;
            this.templateStatusTypeService = templateStatusTypeService;
        }


        /// <summary>
        /// Типы статусов шаблонов
        /// </summary>
        /// <returns></returns>
        [HttpGet(ApiRoutes.TemplateStatusType.GetAll)]
        public async Task<IActionResult> GetAll()
        {
            var statusTypes = await templateStatusTypeService.Get().OrderBy(t => t.Description).ToListAsync();

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

            var response = mapper.Map<List<TemplateStatusTypeResponse>>(statusTypes);

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