using System.Collections.Generic;
using System.Threading.Tasks;
using GxPress.Auth;
using GxPress.Entity;
using GxPress.Repository.Interface;
using GxPress.Request.BlacklistUser;
using GxPress.Service.Interface.IM;
using GxPress.Service.Interface.OftenContact;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace GxPress.Api.AppControllers
{
    /// <summary>
    /// 用户黑名单
    /// </summary>
    [Route("api/app/blacklist")]
    [ApiController]
    [Authorize]
    public class BlacklistController : ControllerBase
    {
        private readonly ILogger<BlacklistController> _logger;
        private readonly IBlacklistUserRepository _blacklistUserRepository;
        private readonly ILoginContext _loginContext;
        private readonly IOftenContactService _oftenContactService;
        private readonly IIMService _imService;

        public BlacklistController(ILogger<BlacklistController> logger,
            IBlacklistUserRepository blacklistUserRepository, ILoginContext loginContext,
            IOftenContactService oftenContactService, IIMService imService)
        {
            _logger = logger;
            _blacklistUserRepository = blacklistUserRepository;
            _loginContext = loginContext;
            _oftenContactService = oftenContactService;
            _imService = imService;
        }

        /// <summary>
        /// 获取黑名单
        /// </summary>
        /// <returns></returns>
        [HttpPost("list")]
        public async Task<IEnumerable<BlacklistUser>> GetBlacklistUser()
        {
            var request = new BlacklistUserSearchRequest { UserId = _loginContext.AccountId };
            return await _blacklistUserRepository.GetBlacklistUserAsync(request);
        }

        /// <summary>
        /// 添加黑名单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("add")]
        public async Task<bool> Insert(BlacklistUserInRequest request)
        {
            return await _imService.AddBlacklistUserAsync(_loginContext.AccountId, request.UserId);
        }
        /// <summary>
        /// 删除黑名单
        /// </summary>
        /// <param name="blackUserId"></param>
        /// <returns></returns>
        [HttpDelete("{blackUserId}")]
        public async Task<bool> Delete(int blackUserId)
        {
            return await _imService.ReMoveBlacklistUserAsync(blackUserId, _loginContext.AccountId);
        }
    }
}