using System.Threading.Tasks;
using GxPress.Auth;
using GxPress.Common.Page;
using GxPress.Repository.Interface;
using GxPress.Request.App.ChatRecord;
using GxPress.Result.App.ChatRecord;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace GxPress.Api.AppControllers
{
    /// <summary>
    /// 聊天信息
    /// </summary>
    [Route("api/app/chat-record")]
    [ApiController]
    [Authorize]
    public class ChatRecordController : ControllerBase
    {
        private readonly ILogger<AppVersionController> _logger;
        private readonly IChatRecordRepository _chatRecordRepository;
        private readonly ILoginContext _loginContext;

        public ChatRecordController(ILogger<AppVersionController> logger, IChatRecordRepository chatRecordRepository,ILoginContext loginContext)
        {
            _logger = logger;
            _chatRecordRepository = chatRecordRepository;
            _loginContext = loginContext;
        }

        /// <summary>
        /// 添加聊天信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("add")]
        public async Task<bool> Insert(ChatRecordInRequest request)
        {
            request.SendUserId = _loginContext.AccountId;
            return await _chatRecordRepository.InsertAsync(request);
        }

        /// <summary>
        /// 聊天消息查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("history")]
        public  async Task<PagedList<ChatRecordSearchHistoryResult>> SearchChatRecordHistoryAsync(ChatRecordSearchHistoryRequest request)
        {
            request.UserId = _loginContext.AccountId;
            return await _chatRecordRepository.SearchChatRecordHistoryAsync(request);
        }
    }
}