using System.Collections.Generic;
using System.Threading.Tasks;
using GxPress.Api.AdminControllers;
using GxPress.Auth;
using GxPress.Entity;
using GxPress.Repository.Interface;
using GxPress.Request.BlacklistArticle;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using GxPress.Service.Interface.BlacklistArticle;
namespace GxPress.Api.AppControllers
{
    /// <summary>
    /// 用户屏蔽文章
    /// </summary>
    [Route("api/app/blacklist-article")]
    [ApiController]
    [Authorize]
    public class BlacklistArticleController : ControllerBase
    {
        private readonly JwtOptions _jwtOptions;
        private readonly ILogger<AdminController> _logger;
        private readonly IBlacklistArticleRepository _blacklistArticleRepository;
        private readonly ILoginContext _loginContext;
        private readonly IBlacklistArticleService _blacklistArticleService;
        public BlacklistArticleController(IOptions<JwtOptions> jwtOptions, ILogger<AdminController> logger, IBlacklistArticleRepository blacklistArticleRepository, ILoginContext loginContext, IBlacklistArticleService blacklistArticleService)
        {
            _jwtOptions = jwtOptions.Value;
            _logger = logger;
            _blacklistArticleRepository = blacklistArticleRepository;
            _loginContext = loginContext;
            _blacklistArticleService = blacklistArticleService;
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("add")]
        public async Task<bool> Insert(BlacklistArticleInRequest request)
        {
            var userId = _loginContext.AccountId;
            return await _blacklistArticleService.InsertAsync(userId, request);
        }

        /// <summary>
        /// 查询用户屏蔽文章类型值
        /// </summary>
        /// <returns></returns>
        [HttpPost("list")]
        public async Task<IEnumerable<BlacklistArticle>> GetList()
        {
            var request = new BlacklistArticleSearchRequest { UserId = _loginContext.AccountId };
            return await _blacklistArticleRepository.GetListAsync(request);
        }
    }
}