You are a helpful assistant.
namespace iRIS.KaskoCore.OSS.Code.Mappers
{
    public class KaskoOssMapper : BaseOssMapper
    {
        protected IServiceProvider ServiceProvider { get; }

        private readonly IPermissionManager _permissionManager;
        private readonly IEntitySettingsManager _settingsManager;
        private readonly IQueryIntegrationLogin _queryIntegrationLogin;
        private readonly IKaskoInspectionOssMapper _inspectionOssMapper;
        private const string _otherBank = "иной банк";

        private readonly IOssKaskoToDealMapper _ossKaskoToDealMapper;

        public KaskoOssMapper(
            IServiceProvider serviceProvider,
            ICustomerMapperFactory customerFactory,
            IPaymentsMapperFactory paymentsFactory,
            IVehicleMapperFactory vehicleFactory,
            ICoversMapperFactory coversFactory,
            IOssKaskoToDealMapper ossKaskoToDealMapper,
            IPermissionManager permissionManager,
            IEntitySettingsManager settingsManager,
            IQueryIntegrationLogin queryIntegrationLogin,
            IKaskoInspectionOssMapper inspectionOssMapper)
            : base(serviceProvider, customerFactory, paymentsFactory, vehicleFactory, coversFactory)
        {
            ServiceProvider = serviceProvider;
            _ossKaskoToDealMapper = ossKaskoToDealMapper;
            _permissionManager = permissionManager;
            _settingsManager = settingsManager;
            _queryIntegrationLogin = queryIntegrationLogin;
            _inspectionOssMapper = inspectionOssMapper;
        }

        protected override void MapDeal(OssUniPolicyDto policyDto, Deal deal, Basket basket, Dictionary<string, object> additionalDictionary)
        {
            base.MapDeal(policyDto, deal, basket, additionalDictionary);
            
            if (HasTelematics(deal))
            {
                policyDto.Telematics = GetTelematics(deal);
            }

            if (IsBox(deal))
            {
                policyDto.BoxType = GetBoxType(deal);
            }

            var kasko = new OssUniKaskoDto();
            MapKasko(kasko, deal);
            policyDto.Kasko = kasko;

            var options = new List<OssUniOptionDto>();
            MapOptions(options, deal);
            policyDto.Options = options;

            //Временное логгирование для DIAUTO-4028
            LogBasket(policyDto, deal, basket);

            MapExtras(policyDto, deal);

            _inspectionOssMapper.MapToUni(policyDto.Vehicle, deal);

            policyDto.DsasCoordinationId = InsuranceApprovalsFormatter.GetApprovalsForExternalSystem(deal.AutoDeal.DIUnderwriterApprovals, deal.AutoDeal.URMApproval);

            // Маппинг данных для ВИ Каско
            MapDataForVI(policyDto, deal, kasko);

            if (KaskoOsagoMapHelper.IsKaskoB2B(basket))
            {
                var b2bKaskoMapper = ServiceProvider.GetRequiredService<IKaskoB2bAdditionalOssMapper>();
                b2bKaskoMapper.MapToUni(policyDto, basket, deal);
            }

            var courier = deal.DealIntermediaries?.SingleOrDefault(i => i.Intermediary != null && i.Intermediary.InteractionTypeCode.InEnum(InteractionTypeEnum.Courier));
            if (courier != null)
            {
                policyDto.NoComissions = MapHelper.ConvertBoolToYesNo(true);
            }

            if (basket.IsLead == true)
            {
                KaskoOsagoMapHelper.ClearParticipants(
                    deal,
                    ServiceProvider,
                    EntitySettingCodes.SendIntermediaryToOssForLead,
                    EntitySettingCodes.SendIntermediaryToOssForLeadDefault,
                    EntitySettingCodes.SendIntermediaryToOssForLeadPartner,
                    policyDto.Participants);
            }

            KaskoOsagoMapHelper.ClearParticipants(
                    deal,
                    ServiceProvider,
                    EntitySettingCodes.SendIntermediaryToOss,
                    EntitySettingCodes.SendIntermediaryToOssDefault,
                    EntitySettingCodes.SendIntermediaryToOssPartner,
                    policyDto.Participants);

            BankIsNotBeneficiary(deal, policyDto.Participants);

            KaskoOsagoMapHelper.RemoveDuplicatesParticipantsBank(policyDto.Participants);
        }

        private void MapDataForVI(OssUniPolicyDto policyDto, Deal deal, OssUniKaskoDto kasko)
        {
            if (deal.IsVI == null || deal.IsVI == false)
            {
                return;
            }

            policyDto.StatusBeginDate = MapHelper.OssDateTimeToString(deal.ChangesStartDate, DateTimeFormat);
            policyDto.AgreementversionidToOss = deal.AutoDeal?.AgreementVersionId?.ToString();
            policyDto.Payments = CreateVIPaymentsDto(deal.DateActual);

            if (deal.EntityContext.TryGetValue("prevSpecialTerm", out var specialTerm))
            {
                policyDto.SpecialTerm = (string)specialTerm;
            }

            if (deal.EntityContext.TryGetValue("prevChannel", out var channel))
            {
                policyDto.Channel = (string)channel;
            }

            if (deal.EntityContext.TryGetValue("agentParticipants", out var agentParticipants))
            {
                foreach (var participant in (List<OssUniCustomerDto>)agentParticipants)
                {
                    var index = policyDto.Participants.FindIndex(x => x.Role == participant.Role);

                    if (index != -1)
                    {
                        policyDto.Participants[index] = participant;
                    }
                    else
                    {
                        policyDto.Participants.Add(participant);
                    }
                }
            }

            if (deal.EntityContext.TryGetValue("prevSpecialProgram", out var specialProgram))
            {
                kasko.SpecialProgram = (OssUniSpecialProgramDto)specialProgram;
            }

            if (deal.EntityContext.TryGetValue("signDate", out string date))
            {
                policyDto.Date = date;
            }

            UpdatePolicyDtoCovers(deal, policyDto);
        }

        private void UpdatePolicyDtoCovers(Deal deal, OssUniPolicyDto policyDto)
        {
            var updatedCovers = policyDto.Covers
                .Select(dtoCover =>
                {
                    var matchingCover = deal.AutoDeal.PreviousOssOptions
                        .FirstOrDefault(cover => cover.OssCode == dtoCover.Code && dtoCover.Premium == 0 && cover.Premium != null);

                    if (matchingCover != null)
                    {
                        dtoCover.Premium = matchingCover.Premium.Value;
                    }

                    return dtoCover;
                })
                .ToList();

            policyDto.Covers = updatedCovers;
        }

        private OssUniPaymentsDto CreateVIPaymentsDto(DateTime? dateActual)
        {
            return new OssUniPaymentsDto
            {
                PremiumPlan = "Единовременно",
                Payments = new List<OssUniPaymentDto>
                {
                    new OssUniPaymentDto
                    {
                        Amount = "0",
                        PaymentDate = MapHelper.OssDateTimeToString(dateActual, DateFormat),
                        PeriodNum = "1",
                    }
                }
            };
        }

        private void MapExtras(OssUniPolicyDto policyDto, Deal deal)
        {
            policyDto.Extras = deal.InsuranceObjects.FirstOrDefault()?.OptionalEquipments.Select(_ =>
                new OssUniEquipmentDto
                {
                    Amount = _.Amount.ToString(),
                    Cost = _.TotalCost.ToString(),
                    Type = _.Name
                }).ToList();
        }

        protected override Deal GetDeal(Basket basket)
        {
            return basket.GetKaskoDeal();
        }

        protected override string GetOssDirectInsurancePacket()
        {
            return "CS/CCP";
        }

        protected override string GetOssInsuranceType(Deal deal)
        {
            return OssInsuranceTypes.Kasko;
        }

        protected override string GetOssProductType(Deal deal)
        {
            return OssProductTypes.Kasko;
        }

        protected override string GetSpecialNotes(Deal deal)
        {
            return OssSpecialTermHelper.GetSpecialTerm(deal);
        }

        protected override void MapToDeal(OssUniPolicyDto policyDto, Basket basket, Deal deal)
        {
            base.MapToDeal(policyDto, basket, deal);

            MapBank(policyDto, deal);

            if (deal.AutoDeal.IsMultidrive == true)
            {
                deal.AutoDeal.DriverMinAge = MapHelper.StringToInt(policyDto.Kasko.StaffDriverAge);
                deal.AutoDeal.DriverMinExperience = MapHelper.StringToInt(policyDto.Kasko.StaffDriverStaj);
            }
        }

        private void MapBank(OssUniPolicyDto policyDto, Deal deal)
        {
            var auto = deal.GetAuto();
            var bankParticipant = policyDto.Participants.FirstOrDefault(x => x.Role == OssConstants.BankRoleCode);

            if (bankParticipant != null)
            {
                auto.IsCreditAuto = true;

                if (string.Equals(bankParticipant.Company.Name, _otherBank, StringComparison.OrdinalIgnoreCase)
                    && policyDto.Participants.Any(c => c.Role == OssConstants.BeneficiaryRoleCode && c.Type == OssConstants.IntermediaryTypeCode))
                {
                    bankParticipant = policyDto.Participants.First(c => c.Role == OssConstants.BeneficiaryRoleCode && c.Type == OssConstants.IntermediaryTypeCode);
                }

                SuggestedBank suggestedBank = null;

                if (deal.IsNotParentDeal())
                {
                    bankParticipant.Company = OssUniReplacer.ReplaceBank(bankParticipant.Company);
                }

                var cqrsMediator = ServiceProvider.GetRequiredService<ICqrsMediator>();
                var daDataHelper = ServiceProvider.GetRequiredService<IDaDataHelper>();

                var bank = cqrsMediator.ResolveQuery<IQueryBank>().GetBankByShortName(bankParticipant.Company.Name);
                if (bank == null && (!deal.IsParentDeal() || bankParticipant.Company.Name.EqualsIgnoreCase(_otherBank)))
                {
                    bank = !string.IsNullOrEmpty(bankParticipant.Company.Inn)
                           ? daDataHelper.GetBankAsync(bankParticipant.Company.Inn).GetAwaiter().GetResult()
                           : daDataHelper.GetBankAsync(bankParticipant.Company.Name).GetAwaiter().GetResult();
                }

                if (bank != null)
                {
                    suggestedBank = new SuggestedBank
                    {
                        Name = bank.Subject.LegalEntity.Name,
                        ShortName = bank.Subject.LegalEntity.ShortName,
                        BIK = bank.BIK,
                        Bank_Id = bank.Id > 0 ? bank.Id : null,
                        Inn = bankParticipant.Company.Inn
                    };
                }
                else if (deal.IsParentDeal())
                {
                    suggestedBank = new SuggestedBank()
                    {
                        Name = bankParticipant.Company.Name,
                        ShortName = bankParticipant.Company.Name,
                        Inn = bankParticipant.Company.Inn
                    };
                }

                if (suggestedBank != null)
                {
                    deal.SetBank(suggestedBank);
                }
            }
            else
            {
                auto.IsCreditAuto = false;
            }
        }

        protected override async Task MapToDealAsync(OssUniPolicyDto policyDto, Basket basket, Deal deal)
        {
            await _ossKaskoToDealMapper.MapAsync(deal, basket.Deals, policyDto);
            basket.Number = policyDto.CurrentId;
        }

        private bool HasTelematics(Deal deal)
        {
            var dealOptions = MapHelper.GetOptionsAndRisksNames(deal).options;

            return (dealOptions.Contains(OptionCodes.SafeDriveTelematic)
                && deal.AutoDeal.TelematicInstalledCode != TelematicInstalledCodes.ClientReject)
                || dealOptions.Contains(OptionCodes.MobileTelematic)
                || dealOptions.Contains(OptionCodes.MileLimit);
        }

        private OssUniTelematicsDto GetTelematics(Deal deal)
        {
            var options = MapHelper.GetOptionsAndRisks(deal).options;
            var mileageLimitOption = options.FirstOrDefault(o => o.ProductOption.OptionCode == OptionCodes.MileLimit);

            if (mileageLimitOption != null)
            {
                return new OssUniTelematicsDto
                {
                    Mileagelimit = mileageLimitOption.SelectValue?.ToString(),
                    Installed = MapHelper.ConvertBoolToYesNo(false)
                };
            }

            return new OssUniTelematicsDto
            {
                Number = deal.AutoDeal.TelematicNumber,
                Type = GetTelematicType(options),
                Installed = MapHelper.ConvertBoolToYesNo(true)
            };
        }

        private string GetTelematicType(List<DealOption> options)
        {
            var optionNames = options.Select(x => x.ProductOption.OptionCode).ToList();

            if (optionNames.Contains(OptionCodes.MobileTelematic))
            {
                return OSSTelematicCodes.MobileTelematic;
            }

            if (optionNames.Contains(OptionCodes.MileLimit))
            {
                return OSSTelematicCodes.MileLimit;
            }

            if (optionNames.Contains(OptionCodes.SafeDriveTelematic))
            {
                return OSSTelematicCodes.SafeDriveTelematic;
            }

            return null;
        }

        private bool IsBox(Deal deal)
        {
            return deal.Proposals.FirstOrDefault(p => p.IsSelected == true).Offer?.IsBox == true;
        }

        private string GetBoxType(Deal deal)
        {
            return deal.Proposals.FirstOrDefault(p => p.IsSelected == true).Offer.BoxName;
        }

        protected virtual void MapKasko(OssUniKaskoDto kasko, Deal deal)
        {
            var compensationOptions = deal.ConditionBlock?.DealCompensationOptions?
                .Select(x => x.ProductCompensationOption.CompensationOptionCode)
                .Where(s => !string.IsNullOrEmpty(s))
                .ToList() ?? new List<string>();

            var optionsAndRisks = MapHelper.GetOptionsAndRisksNames(deal);
            var dealOptions = optionsAndRisks.options;
            var dealRisks = optionsAndRisks.risks;
            var brokenGlass = dealOptions.Contains(OptionCodes.GLASS1T) ? "1 раз в год" :
                              dealOptions.Contains(OptionCodes.GLASSMANY) ? "без ограничений" : null;
            var avarkomCall = dealOptions.Contains(OptionCodes.AVARCOMACCIDENT) ? "на любое ДТП" :
                              dealOptions.Contains(OptionCodes.AVARCOM2PAR) ? "на ДТП с двумя участниками или с пострадавшими по здоровью" :
                              dealOptions.Contains(OptionCodes.AVARCOMANY) ? "на все события" : null;
            var avarkomRef = dealOptions.Contains(OptionCodes.AVARCOMACCIDENT) ? "на ДТП с двумя участниками" :
                              dealOptions.Contains(OptionCodes.AVARCOM2PAR) ? "на все ДТП" : null;

            kasko.Multitype = deal.AutoDeal.IsMultidrive.Value ? "Любые лица" : "Список";
            kasko.SecuritySystem = MapHelper.ConvertBoolToYesNo(deal.GetInsObjectAuto().HasAntiTheftSystem);
            kasko.StoaDealer = MapHelper.ConvertBoolToYesNo(dealOptions.Contains(OptionCodes.DEALERTECHCENTER) || HasMatch(compensationOptions, OptionCodes.DEALERTECHCENTER, OptionCodes.RepairStoaDealer));
            kasko.StoaInsurer = MapHelper.ConvertBoolToYesNo(dealOptions.Contains(OptionCodes.TECHCENTER) || HasMatch(compensationOptions, OptionCodes.TECHCENTER, OptionCodes.RepairStoaNotChoise));
            kasko.StoaInsurant = MapHelper.ConvertBoolToYesNo(HasMatch(compensationOptions, OptionCodes.INSURANTTECHCENTER, OptionCodes.RepairStoaChoise));
            kasko.StoaCalculate = MapHelper.ConvertBoolToYesNo(dealRisks.Contains(RiskCodes.CARJACKING) || dealRisks.Contains(RiskCodes.TOTAL));
            kasko.StaffDriverStaj = "0";
            kasko.StaffDriverAge = "18";
            kasko.Evacuation = MapHelper.ConvertBoolToYesNo(dealOptions.Contains(OptionCodes.EVACUATION));
            kasko.BrokenGlass = brokenGlass;
            kasko.AvarkomCall = avarkomCall;
            kasko.AvarkomRef = avarkomRef;
            kasko.Taxi = MapHelper.ConvertBoolToYesNo(dealOptions.Contains(OptionCodes.TAXI));
            kasko.LeaseAvto = MapHelper.ConvertBoolToYesNo(dealOptions.Contains(OptionCodes.RENT));
            kasko.EvacuationBroken = MapHelper.ConvertBoolToYesNo(dealOptions.Contains(OptionCodes.TECHHELP));
            kasko.WheelChange = MapHelper.ConvertBoolToYesNo(dealOptions.Contains(OptionCodes.TECHHELP));
            kasko.StartEngine = MapHelper.ConvertBoolToYesNo(dealOptions.Contains(OptionCodes.TECHHELP));
            kasko.AddFuel = MapHelper.ConvertBoolToYesNo(dealOptions.Contains(OptionCodes.TECHHELP));
            kasko.InsuredFeedback = MapHelper.ConvertBoolToYesNo(true);
            kasko.BmClass = "0-1";
            kasko.Franchise = MapHelper.ConvertBoolToYesNo(false);
            kasko.NoParking = MapHelper.ConvertBoolToYesNo(false);
            kasko.GibddOrder = MapHelper.ConvertBoolToYesNo(false);
            kasko.Wheelsteal = MapHelper.ConvertBoolToYesNo(false);
            kasko.Pdd = MapHelper.ConvertBoolToYesNo(false);
            kasko.MiniCasco = MapHelper.ConvertBoolToYesNo(deal.IsBox() && dealRisks.Contains(RiskCodes.DMGSECPART));
            kasko.DiscountByKv = MapHelper.DecimalToStringWithEnUsCulture(deal.GetCommissionDiscount());
            kasko.RegionUse = deal.GetAutoRegionOfUsingCode();
            kasko.PersonalManager = MapHelper.ConvertBoolToYesNo(dealOptions.Contains(OptionCodes.PersonalManager));

            var specialProgram = new OssUniSpecialProgramDto();
            MapSpecialProgram(deal, specialProgram);
            if (!string.IsNullOrEmpty(specialProgram.Guid) && !string.IsNullOrEmpty(specialProgram.ProgramName))
            {
                kasko.SpecialProgram = specialProgram;
            }

            bool HasMatch(List<string> collection, params string[] selection) => collection.Intersect(selection).Any();
        }

        protected virtual void MapOptions(List<OssUniOptionDto> options, Deal deal)
        {
            var dealOptions = MapHelper.GetOptionsAndRisksNames(deal)
                .options
                .Select(x => new OssUniOptionDto
                {
                    Key = MapHelper.MapForDictionaryKey(x, MapDictionarys.ProductOptionCodeToOssOptionCodeMapping)
                });

            options.AddRange(dealOptions);
        }

        protected override string GetOssSource(Basket basket, Dictionary<string, object> additionalDictionary)
        {
            var creatorId = _permissionManager.GetUserIdByRelationForObject(PermissionConstants.Relation.Creator, nameof(Basket), basket.EntityId);
            if (creatorId != null)
            {
                var integrationLogin = _queryIntegrationLogin.GetIntegrationLoginByUserId((int)creatorId);
                var special = _settingsManager.GetSettingForDefaultOrPartnerConfiguration<string>(
                    EntitySettingCodes.KaskoOssSourcePredefined,
                    EntitySettingCodes.KaskoOssSourcePredefinedDefault,
                    EntitySettingCodes.KaskoOssSourcePredefinedPartner,
                    integrationLogin,
                    string.Empty);

                if (!string.IsNullOrEmpty(special))
                {
                    return special;
                }
            }

            return base.GetOssSource(basket, additionalDictionary);
        }

        protected override string OssGetPolicyType(Deal deal)
        {
            if (deal?.IsVI == true)
            {
                return ((int)OssConstants.PolicyType.VI).ToString(); //ВИ
            }

            if ((deal.IsProlongation == true || deal.AutoDeal?.IsSubscription == true)
                        && !string.IsNullOrEmpty(deal.AutoDeal?.PreviousPolicyNumber))
            {
                return ((int)OssConstants.PolicyType.Prolongation).ToString();
            }
            else
            {
                return ((int)OssConstants.PolicyType.New).ToString();
            }
        }

        private void MapSpecialProgram(Deal deal, OssUniSpecialProgramDto specialProgramDto)
        {
            specialProgramDto.BsoSign = MapHelper.ConvertBoolToYesNo(false);
            specialProgramDto.Code = "КАСКО";
            var selectedProposalOffer = deal.GetSelectedProposal()?.Offer;
            specialProgramDto.Guid = selectedProposalOffer?.AISProductGuid?.ToString();
            specialProgramDto.ProgramName = GetProgramName(deal, selectedProposalOffer?.Id);
        }

        private string GetProgramName(Deal deal, int? offerId)
        {
            if (!deal.IsBox() && HasDmgSecPartRisk(deal))
            {
                return SpecialProgramNames.KaskoNoPolicyDI;
            }

            var programName = deal.AutoDeal.IsSubscription == true
                ? SpecialProgramNames.KaskoSubscription
                : deal.GetSelectedProposal()?.Offer?.Name;

            if (offerId.HasValue)
            {
                foreach (var offerIdsToProgramName in Constants.OssConstants.MapOfferIdsToProgramName)
                {
                    if (offerIdsToProgramName.Key.Contains(offerId.Value))
                    {
                        return offerIdsToProgramName.Value;
                    }
                }
            }

            return programName;
        }

        private void BankIsNotBeneficiary(Deal deal, List<OssUniCustomerDto> participants)
        {
            var intermediary = deal.GetMainIntermediary();
            if (intermediary == null || !KaskoBankHelper.IsRosbank(deal))
            {
                return;
            }

            var logger = ServiceProvider.GetRequiredService<ILogger>();
            var entitySettingsManager = ServiceProvider.GetRequiredService<IEntitySettingsManager>();
            var isBankIsNotBeneficiary = entitySettingsManager.GetSettingForDefaultOrPartnerConfiguration(
                EntitySettingCodes.BankIsNotBeneficiary,
                EntitySettingCodes.BankIsNotBeneficiaryDefault,
                EntitySettingCodes.BankIsNotBeneficiaryPartner,
                intermediary,
                false,
                logger);

            if (isBankIsNotBeneficiary)
            {
                var participantIntermidiary = participants.FirstOrDefault(c => c.Role == OssConstants.BeneficiaryRoleCode && c.Type == OssConstants.IntermediaryTypeCode);
                var participantIndividual = participants.FirstOrDefault(c => c.Role == OssConstants.BeneficiaryRoleCode && c.Type == OssConstants.IndividualEntityTypeCode);
                if (participantIntermidiary != null && participantIndividual != null)
                {
                    participants.Remove(participantIntermidiary);
                    participants.Remove(participantIndividual);

                    participantIndividual.Covers.AddRange(participantIntermidiary.Covers);
                    participants.Add(participantIndividual);
                }
            }
        }

        private bool HasDmgSecPartRisk(Deal deal)
        {
            var dealHelper = new DealHelper(deal);

            return dealHelper.DealRisks.Any(x => x.ProductRisk.RiskCode == RiskCodes.DMGSECPART);
        }

        private void LogBasket(OssUniPolicyDto policyDto, Deal deal, Basket basket)
        {
            var coverageAC = policyDto.Covers.FirstOrDefault(c => c.Code == "AC");

            if (coverageAC != null && coverageAC.Premium != 0 && !coverageAC.Risks.Any())
            {
                var logger = ServiceProvider.GetRequiredService<ILogger>();

                logger
                    .ForContext("ProcessKey", basket.Number)
                    .ForContext("Basket", JsonSerializer.Serialize(basket))
                    .Information($"Логирование корзины");
            }
        }
    }

Посмотри пожалуйста есть информация как маппится номер телефона и емэйл из осс в сделку?