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

namespace GxPress.Api.AppControllers
{
    /// <summary>
    /// 收藏
    /// </summary>
    [Route("api/app/collection")]
    [ApiController]
    [Authorize]
    public class CollectionController : ControllerBase
    {
        private readonly ILogger<CollectionController> _logger;
        private readonly ICollectionService _collectionService;
        private readonly ILoginContext _loginContext;


        public CollectionController(ILogger<CollectionController> logger, ICollectionService collectionService, ILoginContext loginContext)
        {
            _logger = logger;
            _collectionService = collectionService;
            _loginContext = loginContext;
        }
        /// <summary>
        /// 添加收藏
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut("add")]
        public async Task<bool> Insert(CollectionInRequest request)
        {
            request.UserId = _loginContext.AccountId;
            return await _collectionService.Insert(request);
        }
        /// <summary>
        /// 收藏
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("search")]
        public async Task<PagedList<CollectionListPageResult>> PageList(CollectionPageSearchRequest request)
        {
            request.UserId = _loginContext.AccountId;
            return await _collectionService. PageListAsync(request);
        }

        /// <summary>
        /// 获取收藏详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]

        public async Task<CollectionResult> GetCollectionDetail(int id)
        {
            return await _collectionService.GetCollectionDetailAsync(id);
        }
    }
}