using System.Threading.Tasks;
using GxPress.Auth;
using GxPress.Repository.Interface;
using GxPress.Request.AddressBookGroupUser;
using GxPress.Result.AddressBookGroupUser;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace GxPress.Api.AppControllers
{
    /// <summary>
    /// 通讯录用户信息
    /// </summary>
    [Route("api/app/address-book-group-user")]
    [ApiController]
    [Authorize]
    public class AddressBookGroupUserController : ControllerBase
    {
        private readonly ILogger<AppVersionController> _logger;
        private readonly IAddressBookGroupUserRepository _addressBookGroupUserRepository;
        private readonly ILoginContext _loginContext;
        public AddressBookGroupUserController(ILogger<AppVersionController> logger, IAddressBookGroupUserRepository addressBookGroupUserRepository, ILoginContext loginContext)
        {
            _logger = logger;
            _addressBookGroupUserRepository = addressBookGroupUserRepository;
            _loginContext = loginContext;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public async Task<bool> Delete(int id)
        {
            return await _addressBookGroupUserRepository.DeleteAsync(id);
        }
        /// <summary>
        /// 删除自建分组用户
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete")]
        public async Task<bool> Deletes(AddressBookGroupUserDeleteRequest request)
        {
            return await _addressBookGroupUserRepository.DeletesAsync(request.Ids);
        }
        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("list")]
        public async Task<AddressBookGroupUserListResult> GetAddressBookGroupUserList(
            AddressBookGroupUserSearchRequest request)
        {
            var userId = _loginContext.AccountId;
            return await _addressBookGroupUserRepository.GetAddressBookGroupUserListAsync(request, userId);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("add")]
        public async Task<bool> Insert(AddressBookGroupUserInRequest request)
        {
            return await _addressBookGroupUserRepository.InsertAsync(request);
        }
        /// <summary>
        /// 移动分组成员
        /// </summary>
        /// /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("move")]
        public async Task<bool> AddressBookGroupUserMove(AddressBookGroupUserMoveRequest request)
        {
            return await _addressBookGroupUserRepository.AddressBookGroupUserMoveAsync(request);
        }
    }
}