using Hotline.Caching.Interfaces;
using Hotline.CallCenter.Calls;
using Hotline.CallCenter.Tels;
using Hotline.Share.Dtos.CallCenter;
using Hotline.Share.Enums.CallCenter;
using MapsterMapper;
using Microsoft.AspNetCore.Mvc;
using XF.Domain.Authentications;
using XF.Domain.Repository;

namespace Hotline.Api.Controllers
{
    /// <summary>
    /// 话机相关接口
    /// </summary>
    public class TelController : BaseController
    {
        private readonly IMapper _mapper;
        private readonly IRepository<Tel> _telRepository;
        private readonly IRepository<TelGroup> _telGroupRepository;

        public TelController(
            IMapper mapper,
            IRepository<Tel> telRepository,
            IRepository<TelGroup> telGroupRepository)
        {
            _mapper = mapper;
            _telRepository = telRepository;
            _telGroupRepository = telGroupRepository;
        }

        /// <summary>
        /// 查询分机
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IReadOnlyList<TelDto>> Query()
        {
            return await _telRepository.Queryable()
                  .Select<TelDto>()
                  .ToListAsync(HttpContext.RequestAborted);
        }

        /// <summary>
        /// 查询分机组（技能组）
        /// </summary>
        /// <returns></returns>
        [HttpGet("groups")]
        public async Task<IReadOnlyList<TelGroupDto>> QueryTelGroup()
        {
            var data = await _telGroupRepository.Queryable()//.Includes(d => d.Tels)
              .Select<TelGroupDto>()
              .ToListAsync(HttpContext.RequestAborted);
            return _mapper.Map<IReadOnlyList<TelGroupDto>>(data);
        }
    }
}
