
// 








namespace SafeCampus.Web.Core;

/// <summary>
/// 业务角色管理控制器
/// </summary>
[ApiDescriptionSettings(Tag = "角色管理")]
[Route("biz/organization/role")]
[RolePermission]
public class BizRoleController : IDynamicApiController
{
    private readonly IResourceService _resourceService;
    private readonly IRoleService _roleService;
    private readonly ISysUserService _sysUserService;

    public BizRoleController(IResourceService resourceService, IRoleService roleService, ISysUserService sysUserService)
    {
        _resourceService = resourceService;
        _roleService = roleService;
        _sysUserService = sysUserService;
    }

    /// <summary>
    /// 角色分页查询
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("page")]
    [DisplayName("角色分页查询")]
    public async Task<dynamic> Page([FromQuery] RolePageInput input)
    {
        return await _roleService.Page(input);
    }

    /// <summary>
    /// 添加角色
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("add")]
    [DisplayName("添加角色")]
    public async Task Add([FromBody] RoleAddInput input)
    {
        await _roleService.Add(input);
    }

    /// <summary>
    /// 修改角色
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("edit")]
    [DisplayName("修改角色")]
    public async Task Edit([FromBody] RoleEditInput input)
    {
        await _roleService.Edit(input);
    }

    /// <summary>
    /// 删除角色
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("delete")]
    [DisplayName("删除角色")]
    public async Task Delete([FromBody] BaseIdListInput input)
    {
        await _roleService.Delete(input);
    }

    /// <summary>
    /// 获取角色授权资源树
    /// </summary>
    /// <returns></returns>
    [HttpGet("resourceTreeSelector")]
    [DisplayName("获取角色授权资源树")]
    public async Task<dynamic> ResourceTreeSelector()
    {
        return await _roleService.ResourceTreeSelector();
    }

    /// <summary>
    /// 获取角色拥有资源
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("ownResource")]
    [DisplayName("获取角色拥有资源")]
    public async Task<dynamic> OwnResource([FromQuery] BaseIdInput input)
    {
        return await _roleService.OwnResource(input, CateGoryConst.RELATION_SYS_ROLE_HAS_RESOURCE);
    }

    /// <summary>
    /// 给角色授权资源
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("grantResource")]
    [DisplayName("角色授权资源")]
    public async Task GrantResource([FromBody] GrantResourceInput input)
    {
        await _roleService.GrantResource(input);
    }

    /// <summary>
    /// 获取角色下的用户
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("ownUser")]
    [DisplayName("获取角色下的用户")]
    public async Task<dynamic> OwnUser([FromQuery] BaseIdInput input)
    {
        return await _roleService.OwnUser(input);
    }

    /// <summary>
    /// 给角色授权用户
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("grantUser")]
    [DisplayName("角色授权")]
    public async Task GrantUser([FromBody] GrantUserInput input)
    {
        await _roleService.GrantUser(input);
    }

    /// <summary>
    /// 获取角色树
    /// </summary>
    /// <returns></returns>
    [HttpGet("tree")]
    [DisplayName("获取角色树")]
    public async Task<dynamic> Tree([FromQuery] RoleTreeInput input)
    {
        return await _roleService.Tree(input);
    }


    /// <summary>
    /// 获取角色详情
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("detail")]
    [DisplayName("获取角色详情")]
    public async Task<dynamic> Detail([FromQuery] BaseIdInput input)
    {
        return await _roleService.Detail(input);
    }

    /// <summary>
    /// 获取角色选择器
    /// </summary>
    /// <returns></returns>
    [HttpGet("roleSelector")]
    [DisplayName("获取角色选择器")]
    public async Task<dynamic> RoleSelector([FromQuery] RoleSelectorInput input)
    {
        return await _roleService.RoleSelector(input);
    }
}
