using MapsterMapper;
using Microsoft.AspNetCore.Mvc;
using XF.Domain.Authentications;
using Hotline.Share.Dtos;
using Hotline.Share.Tools;
using Hotline.Application.SpecialNumber;
using Hotline.Share.Dtos.Special;
using Hotline.Settings;
using Hotline.Caching.Interfaces;
using Hotline.Repository.SqlSugar.Extensions;
using Hotline.Share.Dtos.Order;

namespace Hotline.Api.Controllers
{
    /// <summary>
    /// 特殊号码
    /// </summary>
    public class SpecialController : BaseController
    {
        #region 注入

        private readonly IMapper _mapper;
        private readonly ISessionContext _sessionContext;
        private readonly ISpecialNumberApplication _specialNumberApplication;
        private readonly ISystemDicDataCacheManager _sysDicDataCacheManager;


        public SpecialController(
           IMapper mapper,
           ISessionContext sessionContext,
           ISpecialNumberApplication specialNumberApplication,
           ISystemDicDataCacheManager sysDicDataCacheManager)
        {
            _mapper = mapper;
            _sessionContext = sessionContext;
            _specialNumberApplication = specialNumberApplication;
            _sysDicDataCacheManager = sysDicDataCacheManager;
        }

        #endregion

        #region 特殊号码

        /// <summary>
        /// 特殊号码列表
        /// </summary>
        /// <param name="pagedDto"></param>
        /// <returns></returns>
        [HttpGet("number/list")]
        public async Task<PagedDto<SpecialNumberInfoDto>> QueryAllSpecialNumberListAsync([FromQuery] SpecialNumberDto pagedDto)
        {
            var (total, items) = await _specialNumberApplication.QueryAllSpecialNumberListAsync(pagedDto)
                 .ToPagedListAsync(pagedDto.PageIndex, pagedDto.PageSize, HttpContext.RequestAborted);
            return new PagedDto<SpecialNumberInfoDto>(total, _mapper.Map<IReadOnlyList<SpecialNumberInfoDto>>(items));
        }

        /// <summary>
        /// 特殊号码新增
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("number/add")]
        public async Task<string> AddSpecialNumberAsync([FromBody] AddSpecialNumberDto dto)
        {
            return await _specialNumberApplication.AddSpecialNumberAsync(dto, HttpContext.RequestAborted);
        }

        /// <summary>
        /// 特殊号码编辑
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPut("number/update")]
        public async Task UpdateSpecialNumberAsync([FromBody] UpdateSpecialNumberDto dto)
        {
            await _specialNumberApplication.UpdateSpecialNumberAsync(dto, HttpContext.RequestAborted);
        }

        /// <summary>
        /// 特殊号码删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpDelete("number/remove")]
        public async Task RemoveSpecialNumberAsync([FromBody] DelSpecialNumberDto dto)
        {
            await _specialNumberApplication.RemoveSpecialNumberAsync(dto, HttpContext.RequestAborted);
        }

        /// <summary>
        /// 特殊号码详情根据id查询
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("number/info")]
        public async Task<SpecialNumberInfoDto> GetSpecialNumberAsync(string Id)
        {
            return await _specialNumberApplication.GetSpecialNumberAsync(Id, HttpContext.RequestAborted);
        }

        /// <summary>
        /// 特殊号码详情根据号码查询
        /// </summary>
        /// <param name="PhoneNumber"></param>
        /// <returns></returns>
        [HttpGet("number/info/num")]
        public async Task<SpecialNumberInfoDto> GetSpecialNumberByAsync(string PhoneNumber)
        {
            return await _specialNumberApplication.GetSpecialNumberByAsync(PhoneNumber, HttpContext.RequestAborted);
        }

        /// <summary>
        /// 特殊号码[政治身份]basedata
        /// </summary>
        /// <returns></returns>
        [HttpGet("number/basedata")]
        public Dictionary<string, dynamic> GetBaseData()
        {
            return new Dictionary<string, dynamic>
            {
                { "PoliticalIdentity", _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.PoliticalIdentity)}
            };
        }

        #endregion
    }
}

