using System.Collections.Generic;
using System.Threading.Tasks;
using GxPress.Repository.Interface;
using GxPress.Request.Role;
using GxPress.Result.Role;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace GxPress.Api.AdminControllers
{
    /// <summary>
    /// 角色
    /// </summary>
    [Route("api/admin/role")]
    [ApiController]
    [Authorize]
    public class AdminRoleController : ControllerBase
    {
        private readonly IRoleRepository _roleRepository;

        public AdminRoleController(IRoleRepository roleRepository)
        {
            _roleRepository = roleRepository;
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<RoleDetailResult> Add(RoleAddRequest request)
        {
            return await _roleRepository.AddAsync(request);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public async Task<bool> Delete(int id)
        {
            return await _roleRepository.DeleteAsync(id);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut("{id}")]
        public async Task<bool> Update(int id, [FromBody]RoleAddRequest request)
        {
            return await _roleRepository.UpdateAsync(id, request);
        }

        /// <summary>
        /// 详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public async Task<RoleDetailResult> GetDetail(int id)
        {
            return await _roleRepository.GetDetailAsync(id);
        }

        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="groupId"></param>
        /// <returns></returns>
        [HttpGet("list")]
        public async Task<List<RoleDetailResult>> GetList(int groupId)
        {
            return await _roleRepository.GetDetailListAsync(groupId);
        }
    }
}