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.Schedule;
using PARR.Domain.Common.Roles;

namespace PARR.API.Controllers.V1
{
    /// <summary>
    /// Расписание регламентной работы - Тип исключения
    /// </summary>
    [Authorize(Roles = ParrRoles.Administrator.Role)]
    public class ScheduleExcludeTypeController : BaseApiController
    {
        private readonly IMapper mapper;
        private readonly IScheduleExcludeTypeRepository scheduleExcludeTypeService;

        public ScheduleExcludeTypeController(
            IMapper mapper,
            IScheduleExcludeTypeRepository scheduleExcludeTypeService
            )
        {
            this.mapper = mapper;
            this.scheduleExcludeTypeService = scheduleExcludeTypeService;
        }


        /// <summary>
        /// Получить список типов исключений для расписания РР
        /// </summary>
        /// <returns></returns>
        [HttpGet(ApiRoutes.ScheduleExcludeType.GetAll)]
        public async Task<IActionResult> GetAll()
        {
            var query = scheduleExcludeTypeService.Get().OrderBy(t => t.Title);
            var types = await query.ToListAsync();

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

            var response = mapper.Map<List<ScheduleExcludeTypeResponse>>(types);

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

        }

    }
}
