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.Administrator.Role)]
    public class RoleController : BaseApiController
    {
        private readonly IRoleRepository roleService;
        private readonly IMapper mapper;

        public RoleController(
            IRoleRepository roleService,
            IMapper mapper
            )
        {
            this.roleService = roleService;
            this.mapper = mapper;
        }


        /// <summary>
        /// Список ролей пользователей
        /// </summary>
        /// <returns></returns>
        [HttpGet(ApiRoutes.Role.GetAll)]
        public async Task<IActionResult> GetAll()
        {
            var roles = await roleService.Get().OrderBy(t => t.Description).ToListAsync();

            var response = mapper.Map<List<RoleResponse>>(roles);

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