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 ScheduleExcludeTypeCalendarController : BaseApiController
    {
        private readonly IMapper mapper;
        private readonly IScheduleExcludeTypeCalendarRepository scheduleExcludeTypeCalendarService;

        public ScheduleExcludeTypeCalendarController(
             IMapper mapper,
             IScheduleExcludeTypeCalendarRepository scheduleExcludeTypeCalendarService
            )
        {
            this.mapper = mapper;
            this.scheduleExcludeTypeCalendarService = scheduleExcludeTypeCalendarService;
        }


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

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

            var response = mapper.Map<List<ScheduleExcludeTypeCalendarResponse>>(calendars);

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

    }
}
