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

namespace GxPress.Api.AdminControllers
{
    /// <summary>
    /// 角色组
    /// </summary>
    [Route("api/admin/roleGroup")]
    [ApiController]
    [Authorize]
    public class AdminRoleGroupController : ControllerBase
    {
        private readonly IRoleGroupRepository _roleGroupRepository;

        public AdminRoleGroupController(IRoleGroupRepository roleGroupRepository)
        {
            _roleGroupRepository = roleGroupRepository;
        }

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

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

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("list")]
        public async Task<List<RoleGroupDetailResult>> GetList()
        {
            return await _roleGroupRepository.GetDetailListAsync();
        }

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