using Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NPOI.SS.Util;
using OpenAuth.App;
using OpenAuth.Repository.Core;
using OpenAuth.Repository.Domain;
using SqlSugar;

namespace OpenAuth.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SysPositionController : ControllerBase
    {
        SysPositionApp positionApp;
        public SysPositionController(SysPositionApp sysPositionApp)
        {
            positionApp = sysPositionApp;
        }

        /// <summary>
        /// 职级实体查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<SysPosition>> Get(long id)
        {
            return await positionApp.Get(id);
        }

        /// <summary>
        /// 职级查询
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<PageInfo<List<SysPosition>>>> Load([FromQuery] QueryPositonListReq req)
        {
            return await positionApp.Load(req);
        }

        /// <summary>
        /// 职级树
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<TreeItemLong>>> PositionsTree(long groupId)
        {
            return await positionApp.PositionsTree(groupId);
        }

        /// <summary>
        /// 职级添加
        /// </summary>
        /// <param name="pos"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> Add(SysPosition pos)
        {
            return await positionApp.Add(pos);
        }

        /// <summary>
        /// 职级修改
        /// </summary>
        /// <param name="pos"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> Update(SysPosition pos)
        {
            return await positionApp.Update(pos);
        }

        #region 根据部门查询职级
        /// <summary>
        /// 根据部门查询职级
        /// </summary>
        /// <param name="orgid">部门id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<TreeItemLong>>> LoadPositionByOrg(long orgid)
        {
            return await positionApp.LoadPositionByOrg(orgid);
        }
        #endregion
    }
}
