using System.Threading.Tasks;
using GxPress.Common.Page;
using GxPress.Common.Tools;
using GxPress.EnumConst;
using GxPress.Repository.Interface;
using GxPress.Request.Comment;
using GxPress.Result.Comment;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace GxPress.Api.AdminControllers
{
    /// <summary>
    /// 文章评论 通知评论
    /// </summary>
    [Route("api/admin/comment")]
    [ApiController]
    [Authorize]
    public class AdminCommentController : Controller
    {
        private readonly ICommentRepository _commentRepository;
        public AdminCommentController(ICommentRepository commentRepository)
        {
            _commentRepository = commentRepository;
        }


        /// <summary>
        /// 分页显示数据
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("page")]
        public async Task<PagedList<CommentPageResult>> GetPagedList([FromBody] CommentSearchPageRequest request)
        {
            return await _commentRepository.GetPagedList(request);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete("delete")]
        public async Task<bool> Delete([FromBody] CommentDeleteRequest request)
        {
            return await _commentRepository.DeleteCommentAsync(request);
        }
        /// <summary>
        /// 后台评论分页列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("list")]
        public async Task<PagedList<CommentResult>> GetAllAsync(CommentSearchRequest request)
        {
            var result = await _commentRepository.GetAllAsync(request);
            foreach (var item in result.Items)
            {
                item.TypeValueString = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
            }
            return result;
        }
    }
}