using DataSharing.CityStateDataExchange;
using DataSharing.SendTask;
using DataSharing.SendTask.OtherPlatforms;
using DataSharing.YiBin.Enterprise;
using DataSharing.YiBin.ZzptPlatformsYB;
using Hotline.Share.Dtos.Order;
using Hotline.Share.Enums.Order;
using Microsoft.Extensions.Logging;

namespace DataSharing.YiBin
{
    /// <summary>
    /// 执行推送任务
    /// </summary>
    public class YiBinSendTaskDataService : ISendTaskDataService
    {
        private readonly ILogger<YiBinSendTaskDataService> _logger;
        private readonly IEnterprisePusherProviderService _enterprisePusherProviderService;
        private readonly ICityStateDataExchangePusherProviderService _dataExchangePusherProviderService;
        private readonly IZzptPusherProviderService _zzptPusherProviderService;
        private readonly ISharingConfigurationManager _sharingConfigurationManager;
        private readonly IEnterpriseService _enterpriseService;
        private readonly IZzptService _zzptService;
        private readonly ICityStateDataExchangeService _cityStateDataExchangeService;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="pusherProviderService"></param>
        /// <param name="enterprisePusherProviderService"></param>
        /// <param name="dataExchangePusherProviderService"></param>
        /// <param name="zzptPusherProviderService"></param>
        public YiBinSendTaskDataService(ILogger<YiBinSendTaskDataService> logger,
         IEnterprisePusherProviderService enterprisePusherProviderService,
         ICityStateDataExchangePusherProviderService dataExchangePusherProviderService,
         IZzptPusherProviderService zzptPusherProviderService,
         ISharingConfigurationManager sharingConfigurationManager,
              IEnterpriseService enterpriseService,
              IZzptService zzptService,
              ICityStateDataExchangeService cityStateDataExchangeService)
        {
            _logger = logger;
            _enterprisePusherProviderService = enterprisePusherProviderService;
            _dataExchangePusherProviderService = dataExchangePusherProviderService;
            _zzptPusherProviderService = zzptPusherProviderService;
            _sharingConfigurationManager = sharingConfigurationManager;
            _enterpriseService = enterpriseService;
            _zzptService = zzptService;
            _cityStateDataExchangeService = cityStateDataExchangeService;
        }

        /// <summary>
        /// 执行推送任务
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task SendTask(DsWaitSendTaskOtherPlatforms dto, CancellationToken cancellationToken)
        {
            if (dto is null)
                return;
            _logger.LogInformation("这里是宜宾的服务--------------------------------------");
            switch (dto.PlatformSource)
            {
                case Share.Enums.EPlatformSource.Police110:
                    break;
                //case Share.Enums.EPlatformSource.CityDataExchange:
                //    await _dataExchangePusherProviderService.SendDataExchangeDataPusher(dto, cancellationToken);
                //    break;
                case Share.Enums.EPlatformSource.ConvergenceMedia:
                    break;
                case Share.Enums.EPlatformSource.Enterprise:
                    await _enterprisePusherProviderService.SendEnterpriseDataPusher(dto, cancellationToken);
                    break;
                case Share.Enums.EPlatformSource.ZZPT:
                    await _zzptPusherProviderService.SendDataPusher(dto, cancellationToken);
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 宜宾其他推送
        /// </summary>
        /// <param name="Key"></param>
        /// <param name="order"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task OtherSendTask(string Key, OrderDto order, CancellationToken cancellationToken)
        {
            //需要判断是否需要往企业专班提交数据
            if (Key == "001181")
                //企业专班提交数据
                await _enterpriseService.InitEnterpriseDataAsync(order, cancellationToken);

            //综治平台
            if (Key == "001143")
                await _zzptService.InitZzptPlatformsAsync(order, cancellationToken);
        }

        /// <summary>
        /// 企业服务撤单
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task RevokeOrderAsync(PublishSpecialDto dto, CancellationToken cancellationToken)
        {
            //企业服务
            if (dto.Special.OrgId == "001181")
            {
                await _enterpriseService.EnterpriseRevokeOrderAsync(dto, cancellationToken);
            }
        }

        /// <summary>
        /// 推送办理结果
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task AddHandleOpinion(OrderFlowDto dto, CancellationToken cancellationToken)
        {
            //综治平台推送办理结果
            if (dto.Order.Source == ESource.ZZPT)
            {
                await _zzptService.InitZzptPlatformsDetailAsync(dto, cancellationToken);
            }
            //市州互转推送办结结果
            if (dto.Order.Source == ESource.CityDataExchangeLz || dto.Order.Source == ESource.CityDataExchangeZG)
                await _cityStateDataExchangeService.UndertakAdviceAsync(dto.Order, cancellationToken);
        }

        /// <summary>
        /// 市州互转
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="PlatformSource"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task TranspondCityAsync(OrderDto dto, CancellationToken cancellationToken)
        {
            //数据推送
            await _cityStateDataExchangeService.InitCityDataAsync(dto, cancellationToken);
        }

        /// <summary>
        /// 推送办理结果（泸州市政府门户网站）
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task AddHandleOpinionByCityPortal(OrderFlowDto dto, CancellationToken cancellationToken)
        {
            return Task.CompletedTask;
        }
    }
}
