using System.Collections.Generic;
using System.Threading.Tasks;
using GxPress.Request.Inbox;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using GxPress.Repository.Interface;
using GxPress.Auth;

namespace GxPress.Api.AppControllers
{
    /// <summary>
    /// 收件箱
    /// </summary>
    [Route("api/app/inbox")]
    [ApiController]
    [Authorize]
    public class InboxController : ControllerBase
    {
        private readonly IMiddleRepository middleRepository;
        private readonly ILoginContext _loginContext;
        public InboxController(IMiddleRepository middleRepository, ILoginContext loginContext)
        {
            this.middleRepository = middleRepository;
            _loginContext = loginContext;
        }

        /// <summary>
        /// 搜索
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("search")]
        public async Task<IEnumerable<Entity.Middle.Middle>> Search(InboxSearchRequest request)
        {
            request.UserId = _loginContext.AccountId;
            return await middleRepository.FindAsync(request);
        }
    }
}