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

namespace GxPress.Api.AdminControllers
{
    [Route("api/admin/system-role")]
    [ApiController]
    [Authorize]
    public class AdminSystemRoleController : Controller
    {
        private readonly IRoleService roleService;
        public AdminSystemRoleController(IRoleService roleService)
        {
            this.roleService = roleService;

        }

        /// <summary>
        /// 添加权限菜单关联
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        [HttpPost("add-role-menus")]
        public async Task<bool> InsertSystemRoleMenusAsync(SystemRoleMenusInRequest models)
        {
            return await roleService.InsertSystemRoleMenusAsync(models);
        }

        /// <summary>
        /// 添加 角色和权限
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("add-role")]
        public async Task<bool> InsertSystemRoleAsync(RoleInRequest request)
        {
            return await roleService.InsertSystemRoleAsync(request);
        }
        /// <summary>
        /// 获取所有角色
        /// </summary>
        /// <returns></returns>
        [HttpGet("role")]
        public async Task<List<SystemRoleResult>> GetSystemRoleAllAsync()
        {
            return await roleService.GetSystemRoleAllAsync();
        }
        /// <summary>
        /// 修改角色 权限
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut("update-role")]
        public async Task<bool> UpdateSystemRoleAsync(RoleInRequest request)
        {
            return await roleService.UpdateSystemRoleAsync(request);
        }
        /// <summary>
        /// 删除权限
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("role/{id}")]
        public async Task<bool> DeleteSystemRoleAsync(int id)
        {
            return await roleService.DeleteSystemRoleAsync(id);
        }
        /// <summary>
        /// 添加菜单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost("add-menu")]
        public async Task<bool> InsertMenusAsync([FromBody] List<MenuInRequest> model)
        {
            return await roleService.InsertMenusAsync(model);
        }
        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPut("update-menu")]
        public async Task<bool> UpdateMenusAsync(Entity.Menus.Menus model)
        {
            return await roleService.UpdateMenusAsync(model);
        }
        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("delete-menu")]
        public async Task<bool> DeleteMenusAsync(int id)
        {
            return await roleService.DeleteMenusAsync(id);
        }
        /// <summary>
        /// 根据权限ID获取菜单
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        [HttpGet("menus/{roid}")]
        public async Task<List<MenuInResult>> GetMenusAllAsync(int roleId)
        {
            //获取
            return await roleService.GetMenusAllAsync(roleId);
        }

        /// <summary>
        /// 获取所有菜单
        /// </summary>
        /// <returns></returns>
        [HttpGet("menus")]
        public async Task<IEnumerable<Entity.Menus.Menus>> GetMenusAllAsync()
        {
            return await roleService.GetMenusAllAsync();
        }
    }
}