using System.Threading.Tasks;
using GxPress.Auth;
using GxPress.Common.Page;
using GxPress.Entity.WaitHandle;
using GxPress.Request.App.WaitHandle;
using GxPress.Result.App.WaitHandle;
using GxPress.Service.Interface.WaitHandle;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace GxPress.Api.AppControllers
{
    /// <summary>
    /// 待办事项
    /// </summary>
    [Route("api/app/wait-handle")]
    [ApiController]
    [Authorize]
    public class WaitHandleController : ControllerBase
    {
        private readonly IWaitHandleService _waitHandleService;
        private readonly ILoginContext _loginContext;

        public WaitHandleController(IWaitHandleService waitHandleService, ILoginContext loginContext)
        {
            _waitHandleService = waitHandleService;
            _loginContext = loginContext;
        }

        /// <summary>
        /// 添加修改待办事项
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut("add-update")]
        public async Task<WaitHandle> AddOrUpdateWaitHandleAsync(WaitHandleAddOrUpdateRequest request)
        {
            request.UserId = _loginContext.AccountId;
            return await _waitHandleService.AddOrUpdateWaitHandleAsync(request);
        }
        /// <summary>
        /// 删除待办事项
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete")]
        public async Task<bool> DeleteWaitHandleAsync(DeleteWaitHandleRequest request)
        {
            return await _waitHandleService.DeleteWaitHandleAsync(request);
        }

        /// <summary>
        ///  待办搜索  Sort ：hand  手动 time按时间 label 标签 level 优先级
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("page")]
        public async Task<PagedList<WaitHandle>> PageWaitHandleAsync(PageWaitHandleRequest request)
        {
            request.UserId = _loginContext.AccountId;
            return await _waitHandleService.PageWaitHandleAsync(request);
        }
        /// <summary>
        /// 添加修改标签
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut("add-update-label")]
        public async Task<bool> AddOrUpdateWaitHandleLabelAsync(WaitHandleLabelAddOrUpdateRequest request)
        {
            request.UserId = _loginContext.AccountId;
            return await _waitHandleService.AddOrUpdateWaitHandleLabelAsync(request);
        }
        /// <summary>
        /// 删除标签
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete("delete-label")]
        public async Task<bool> DeleteWaitHandleLabelAsync(DeleteWaitHandleRequest request)
        {
            return await _waitHandleService.DeleteWaitHandleLabelAsync(request);
        }


        /// <summary>
        /// 标签
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("page-label")]
        public async Task<PagedList<WaitHandleLabel>> PageWaitHandleLabelAsync(
            PageWaitHandleRequest request)
        {
            request.UserId = _loginContext.AccountId;
            return await _waitHandleService.PageWaitHandleLabelAsync(request);
        }

        /// <summary>
        /// 待办搜索  1  手动 2 按时间 3 标签 4 优先级
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("list")]
        public async Task<WaitHandleListResult> WaitHandleListAsync(ListWaitHandleRequest request)
        {
            request.UserId = _loginContext.AccountId;
            return await _waitHandleService.WaitHandleListAsync(request);
        }

        /// <summary>
        /// 设置待办事项
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut("set/{id}")]
        public async Task<bool> IsFinishAsync(int id)
        {
            return await _waitHandleService.IsFinishAsync(id);
        }
    }
}