using System.Threading.Tasks;
using GxPress.Auth;
using GxPress.Entity;
using GxPress.Repository.Interface;
using GxPress.Request.Feedback;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace GxPress.Api.AppControllers
{
    /// <summary>
    /// 意见反馈
    /// </summary>
    [Route("api/app/Feedback")]
    [ApiController]
    [Authorize]
    public class FeedbackController : ControllerBase
    {
        private readonly ILogger<AppVersionController> _logger;
        private readonly IFeedbackRepository _feedbackRepository;
        private readonly ILoginContext _loginContext;
        public FeedbackController(ILogger<AppVersionController> logger, IFeedbackRepository feedbackRepository,ILoginContext loginContext)
        {
            _logger = logger;
            _feedbackRepository = feedbackRepository;
            _loginContext = loginContext;
        }

        ///// <summary>
        ///// 查询分页数据
        ///// </summary>
        ///// <param name="request"></param>
        ///// <returns></returns>
        //[HttpPost("page")]
        //[AllowAnonymous]
        //public async Task<PagedList<FeedbackPageResult>> GetPageList([FromBody] FeedbackPageRequest request)
        //{
        //    return await _feedbackRepository.GetPagedList(request);
        //}
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut("add")]
        public async Task<bool> Add([FromBody] FeedbackInRequest request)
        {
            request.UserId = _loginContext.AccountId;
            var feedback = new Feedback
            {
                UserId = request.UserId, Content = request.Content, FeedbackType = request.FeedbackType
            };
            return await _feedbackRepository.InsertAsync(feedback) > 0;
        }
    }
}