using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Nirvana.Common;
using Nirvana.Common.ApiBase;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using YBDevice.Entity;

namespace YBDevice.Application.SystemInfo
{
    /// <summary>
    /// 系统管理
    /// </summary>
    [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
    public class SystemAppService : IDynamicApiController
    {
        private readonly ISystemService _Service;
        public SystemAppService(ISystemService Service)
        {
            _Service = Service;
        }
        /// <summary>
        /// 获取菜单列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetMenuListAsync()
        {
            var data = await _Service.GetMenuListAsync();
            var treeList = new List<TreeSelectModel>();
            foreach (var item in data)
            {
                TreeSelectModel treeModel = new TreeSelectModel();
                treeModel.id = item.Id + "";
                treeModel.text = item.Name;
                treeModel.parentId = item.ParentId + "";
                treeModel.data = item;
                treeList.Add(treeModel);
            }
            var result = treeList.TreeSelectGuidJson();
            return new ResultInfo(ResultState.SUCCESS, "success", result);
        }
        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [QueryParameters]
        public async Task<ResultInfo> DelMenuAsync(Guid id)
        {
            var result = await _Service.DeleteMenuAsync(id);
            return result;
        }
        /// <summary>
        /// 菜单编辑
        /// </summary>
        /// <param name="yB_Menu"></param>
        /// <returns></returns>
        public async Task<ResultInfo> SubmitMenuFormAsync(YB_nMenu yB_Menu)
        {
            var result = await _Service.SubmitMenuFormAsync(yB_Menu);
            return result;
        }

        /// <summary>
        /// 获取角色列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetRoleListAsync(QueryParams queryParams)
        {
            var data = await _Service.GetRoleListAsync(queryParams);
            return new ResultInfo(ResultState.SUCCESS, "success", data);
        }
        /// <summary>
        /// 角色编辑
        /// </summary>
        /// <param name="roleSubmitModel"></param>
        /// <returns></returns>
        public async Task<ResultInfo> SubmitRoleFormAsync(RoleSubmitModel roleSubmitModel)
        {
            var result = await _Service.SubmitRoleFormAsync(roleSubmitModel);
            return result;
        }
        /// <summary>
        /// 角色详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [QueryParameters]
        public async Task<ResultInfo> DetailRoleAsync(Guid id)
        {
            var result = await _Service.DetailRoleAsync(id);
            return new ResultInfo(ResultState.SUCCESS, "success", result);
        }

        /// <summary>
        /// 获取菜单按钮列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetActionListAsync(QueryParams queryParams)
        {
            var result = await _Service.GetActionListAsync(queryParams);
            return new ResultInfo(ResultState.SUCCESS, "success", result);
        }
        /// <summary>
        /// 角色菜单修改
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task<ResultInfo> SubmitMenuActionAsync(YB_nMenuAction data)
        {
            return await _Service.SubmitMenuActionAsync(data);
        }
        /// <summary>
        /// 删除角色菜单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [QueryParameters]
        public async Task<ResultInfo> DeleteMenuActionAsync(Guid id)
        {
            return await _Service.DeleteMenuActionAsync(id);
        }
    }
}
