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

namespace GxPress.Api.AdminControllers
{
    /// <summary>
    /// 通知
    /// </summary>
    [Route("api/admin/notice")]
    [ApiController]
    [Authorize]
    public class AdminNoticeController : ControllerBase
    {
        private readonly INoticeRepository _noticeRepository;

        private readonly INoticeService _noticeServivce;
        public AdminNoticeController(INoticeRepository noticeRepository,ILoginContext loginContext,INoticeService noticeService)
        {
            _noticeRepository = noticeRepository;
            _noticeServivce=noticeService;
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("list")]
        public async Task<PagedList<NoticeListPageResult>> GetNoticeByUserId(NoticePageSearchRequest request)
        {
            return await _noticeRepository.GetAdminNoticeByUserIdAsync(request);
        }

        /// <summary>
        /// 管理员删除通知
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public async Task<bool> AdminDelete(int id)
        {
            return await _noticeRepository.AdminDeleteAsync(id);
        }

        /// <summary>
        /// 获取通知详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("detail/{id}")]
        public async Task<Result.Notice.NoticeDetailResult> GetNoticeDetailResult(int id)
        {
            return await _noticeServivce.GetNoticeDetailResultAsync(id,0);
        }
        /// <summary>
        ///  修改通知
        /// </summary>
        /// <param name="id"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut("{id}")]
        public async Task<bool> UpdateNoticeAsync(int id,[FromBody] Notice request)
        {
            return await _noticeRepository.UpdateNoticeAsync(request);
        }
    }
}