using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using iRIS.InsuranceCore.OSS.Code.Dto.Deserialization;
using iRIS.InsuranceCore.OSS.Code.Dto.OssSearchPolicy;
using iRIS.InsuranceCore.OSS.Code.Dto.Uni;
using iRIS.InsuranceCore.OSS.Code.Mappers;

namespace iRIS.InsuranceCore.OSS.Code.Dto
{
    public static class DtoConverter
    {
        public static OssUniDto Convert(OssUniDeserializationDto deserializationDto)
        {
            return new OssUniDto
            {
                Policy = ConvertPolicy(deserializationDto.Policy)
            };
        }

        public static PolicyHeaderDto Convert(PolicyHeaderDeserializationDto header)
        {
            if (header?.Rows == null)
            {
                return new PolicyHeaderDto();
            }

            var currencyPattern = new Regex(@"\s[a-zA-Z]*", RegexOptions.Compiled);
            return new PolicyHeaderDto
            {
                Rows = header.Rows.Select(x => new PolicyHeaderRowDto
                {
                    PolicyNumber = x.Number,
                    StartDate = MapHelper.ConvertToDateTime(x.StartDate),
                    EndDate = MapHelper.ConvertToDateTime(x.EndDate),
                    PolicyType = x.Type,
                    SellingChannel = x.SellingChannel,
                    SiebelId = x.PhisSiebelID,
                    Premium = MapHelper.ConvertToDecimal(currencyPattern.Replace(x.FinalPremium, string.Empty)),
                    Status = x.PStatus
                })
                .ToList()
            };
        }

        public static OssUniPolicyProlCoeffDto ConvertPolicyProlCoeff(OssUniProlCoeffDeserializationDto prolCoeff)
        {
            if (prolCoeff == null)
            {
                return null;
            }

            return new OssUniPolicyProlCoeffDto
            {
                AccidentCount = prolCoeff.AccidentCount,
                Comission = prolCoeff.Comission,
                KpngDi = prolCoeff.KpngDi,
                KpngB2b = prolCoeff.KpngB2b,
                Lr = prolCoeff.Lr,
                Sku = prolCoeff.Sku
            };
        }

        private static OssUniPolicyDto ConvertPolicy(OssUniPolicyDeserializationDto policy)
        {
            if (policy == null)
            {
                return null;
            }

            return new OssUniPolicyDto
            {
                ActiveDate = policy.ActiveDate,
                AgreementversionidFromOss = policy.AgreementversionidFromOss,
                AgreementversionidToOss = policy.AgreementversionidToOss,
                AisRsaAddendumId = policy.AisRsaAddendumId,
                AisRsaContractId = policy.AisRsaContractId,
                BsoNumber = policy.BsoNumber,
                BsoResponsible = policy.BsoResponsible,
                Chain = policy.Chain,
                Channel = policy.Channel,
                Covers = ConvertCovers(policy.Covers),
                CreationDate = policy.CreationDate,
                Currency = policy.Currency,
                CurrentId = policy.CurrentId,
                Date = policy.Date,
                Department = policy.Department,
                NoComissions = policy.NoComissions,
                DirectInsurance = ConvertDirectInsurance(policy.DirectInsurance),
                DsasCoordinationId = policy.DsasCoordinationId,
                Electronic = policy.Electronic,
                EmergencyMode = policy.EmergencyMode,
                EndDate = policy.EndDate,
                InsuranceKind = policy.InsuranceKind,
                Kasko = ConvertKasko(policy.Kasko),
                MessageId = policy.MessageId,
                Mistakes = ConvertMistakes(policy.Mistakes),
                Number = policy.Number,
                OperationType = policy.OperationType,
                Options = ConvertOptions(policy.Options),
                Osago = ConvertOsago(policy.Osago),
                Participants = ConvertParticipants(policy.Participants),
                Payments = ConvertPayments(policy.Payments),
                PolicyStatus = policy.PolicyStatus,
                PolicyType = policy.PolicyType,
                PremierId = policy.PremierId,
                PremiumList = ConvertPremiumList(policy.PremiumList),
                PrevNumber = policy.PrevNumber,
                PrevPolicyCompany = policy.PrevPolicyCompany,
                PrevPolicyDateEnd = policy.PrevPolicyDateEnd,
                PrevPolicyDateStart = policy.PrevPolicyDateStart,
                Product = policy.Product,
                RsaErrors = policy.RsaErrors,
                RsaKbm = ConvertRsaKbm(policy.RsaKbm),
                RsaPolicyId = policy.RsaPolicyId,
                Sfa = ConvertSfa(policy.Sfa),
                Source = policy.Source,
                SpecialTerm = policy.SpecialTerm,
                StartDate = policy.StartDate,
                StatusBeginDate = policy.StatusBeginDate,
                Telematics = ConvertTelematics(policy.Telematics),
                TimeSale = policy.TimeSale,
                Vehicle = ConvertVehicle(policy.Vehicle),
                Extras = ConvertExtras(policy.Extras),
                OssId = policy.OssId,
                IssueDate = policy.IssueDate,
                Prolcoeff = ConvertPolicyProlCoeff(policy.ProlCoeff)
            };
        }

        private static List<OssUniEquipmentDto> ConvertExtras(List<OssUniEquipmentDeserializationDto> extras)
        {
            if (extras == null)
            {
                return null;
            }

            return extras.Select(x =>
                new OssUniEquipmentDto
                {
                    Amount = x.Amount,
                    Cost = x.Cost,
                    Type = x.Type,
                    Model = x.Model,
                })
                .ToList();
        }

        private static List<OssUniCoverDto> ConvertCovers(List<OssUniCoverDeserializationDto> covers)
        {
            if (covers == null)
            {
                return null;
            }

            return covers.Select(x =>
                new OssUniCoverDto
                {
                    Code = x.Code,
                    CostSum = x.CostSum,
                    Premium = x.Premium,
                    Rates = ConvertRates(x.Rates),
                    Restrictions = ConvertRestrictions(x.Restrictions),
                    Risks = x.Risks
                })
                .ToList();
        }

        private static List<OssUniRateDto> ConvertRates(List<OssUniRateDeserializationDto> rates)
        {
            if (rates == null)
            {
                return null;
            }

            return rates.Select(x =>
                new OssUniRateDto
                {
                    Code = x.Code,
                    Name = x.Name,
                    Value = x.Value
                })
                .ToList();
        }

        private static List<OssUniRestrictionDto> ConvertRestrictions(List<OssUniRestrictionDeserializationDto> restrictions)
        {
            if (restrictions == null)
            {
                return null;
            }

            return restrictions.Select(x =>
                new OssUniRestrictionDto
                {
                    Currency = x.Currency,
                    Value = x.Value,
                    Name = x.Name,
                    Type = x.Type
                })
                .ToList();
        }

        private static OssUniDirectInsuranceDto ConvertDirectInsurance(OssUniDirectInsuranceDeserializationDto directInsurance)
        {
            if (directInsurance == null)
            {
                return null;
            }

            return new OssUniDirectInsuranceDto
            {
                Calcnum = directInsurance.Calcnum,
                Packet = directInsurance.Packet,
                SiebelId = directInsurance.SiebelId
            };
        }

        private static OssUniSfaDto ConvertSfa(OssUniSfaDeserializationDto sfa)
        {
            if (sfa == null)
            {
                return null;
            }

            return new OssUniSfaDto
            {
                Calcnum = sfa.Calcnum,
                SiebelId = sfa.SiebelId
            };
        }

        private static OssUniKaskoDto ConvertKasko(OssUniKaskoDeserializationDto kasko)
        {
            if (kasko == null)
            {
                return null;
            }

            return new OssUniKaskoDto
            {
                AddFuel = kasko.AddFuel,
                AvarkomCall = kasko.AvarkomCall,
                AvarkomRef = kasko.AvarkomRef,
                BmClass = kasko.BmClass,
                BrokenGlass = kasko.BrokenGlass,
                CitySale = kasko.CitySale,
                RegionUse = kasko.RegionUse,
                CorrectCoeff = kasko.CorrectCoeff,
                DiscountByKv = kasko.DiscountByKv,
                Evacuation = kasko.Evacuation,
                EvacuationBroken = kasko.EvacuationBroken,
                Franchise = kasko.Franchise,
                FranchiseAgeExp = kasko.FranchiseAgeExp,
                GibddOrder = kasko.GibddOrder,
                InsuredFeedback = kasko.InsuredFeedback,
                LeaseAvto = kasko.LeaseAvto,
                MiniCasco = kasko.MiniCasco,
                Multitype = kasko.Multitype,
                NoParking = kasko.NoParking,
                Pdd = kasko.Pdd,
                SecuritySystem = kasko.SecuritySystem,
                SpecialProgram = ConvertSpecialProgram(kasko.SpecialProgram),
                StaffDriverAge = kasko.StaffDriverAge,
                StaffDriverStaj = kasko.StaffDriverStaj,
                StartEngine = kasko.StartEngine,
                StoaCalculate = kasko.StoaCalculate,
                StoaDealer = kasko.StoaDealer,
                StoaInsurant = kasko.StoaInsurant,
                StoaInsurer = kasko.StoaInsurer,
                Taxi = kasko.Taxi,
                WheelChange = kasko.WheelChange,
                Wheelsteal = kasko.Wheelsteal,
                PersonalManager = kasko.PersonalManager,
            };
        }

        private static OssUniSpecialProgramDto ConvertSpecialProgram(OssUniSpecialProgramDeserializationDto specialProgram)
        {
            if (specialProgram == null)
            {
                return null;
            }

            return new OssUniSpecialProgramDto
            {
                BsoSign = specialProgram.BsoSign,
                Code = specialProgram.Code,
                Guid = specialProgram.Guid,
                ProgramName = specialProgram.ProgramName
            };
        }

        private static List<OssUniMistakeDto> ConvertMistakes(List<OssUniMistakeDeserializationDto> mistakes)
        {
            if (mistakes == null)
            {
                return null;
            }

            return mistakes.Select(x =>
                new OssUniMistakeDto
                {
                    Code = x.Code,
                    Comment = x.Comment,
                    Reason = x.Reason
                })
                .ToList();
        }

        private static List<OssUniOptionDto> ConvertOptions(List<OssUniOptionDeserializationDto> options)
        {
            if (options == null)
            {
                return null;
            }

            return options.Select(x => new OssUniOptionDto { Key = x.Key }).ToList();
        }

        private static OssUniOsagoDto ConvertOsago(OssUniOsagoDeserializationDto osago)
        {
            if (osago == null)
            {
                return null;
            }

            return new OssUniOsagoDto
            {
                BmClass = osago.BmClass,
                Kbm = osago.Kbm,
                TrailerSign = osago.TrailerSign,
                UsagePeriod = ConvertPeriods(osago.UsagePeriod),
                SpecialProgram = osago.SpecialProgram != null ? new OssUniSpecialProgramDto()
                {
                    BsoSign = osago.SpecialProgram.BsoSign,
                    ProgramName = osago.SpecialProgram.ProgramName,
                    Guid = osago.SpecialProgram.Guid,
                    Code = osago.SpecialProgram.Code,
                }
                : null,
                RsaReinsurance = osago.RsaReinsurance,
                IsOsagoNetto = osago.IsOsagoNetto,
                RsaErrorReinsurance = osago.RsaErrorReinsurance,
                RsaPrimaryDrivingArea = osago.RsaPrimaryDrivingArea,
                IsShort = osago.IsShort
            };
        }

        private static List<OssUniPeriodDto> ConvertPeriods(List<OssUniPeriodDeserializationDto> periods)
        {
            if (periods == null)
            {
                return null;
            }

            return periods.Select(x =>
                new OssUniPeriodDto
                {
                    Start = x.Start,
                    End = x.End
                })
                .ToList();
        }

        private static List<OssUniCustomerDto> ConvertParticipants(List<OssUniCustomerDeserializationDto> customers)
        {
            if (customers == null)
            {
                return null;
            }

            return customers.Select(x =>
                new OssUniCustomerDto
                {
                    CashbookId = x.CashbookId,
                    Comissions = ConvertComissions(x.Comissions),
                    Company = ConvertCompany(x.Company),
                    ContractorId = x.ContractorId,
                    CountryCode = x.CountryCode,
                    Covers = x.Covers,
                    Curator = x.Curator,
                    Person = ConvertPerson(x.Person),
                    Requisites = ConvertRequisites(x.Requisites),
                    Role = x.Role,
                    RolePrm = x.RolePrm,
                    RsaCheckId = x.RsaCheckId,
                    RsaKbm = ConvertRsaKbm(x.RsaKbm),
                    SiebelId = x.SiebelId,
                    Type = x.Type,
                    UniqueId = x.UniqueId,
                    IsResident = x.IsResident
                })
                .ToList();
        }

        private static OssUniComissionsDto ConvertComissions(OssUniComissionsDeserializationDto comissions)
        {
            if (comissions == null)
            {
                return null;
            }

            return new OssUniComissionsDto
            {
                Comission = ConvertComission(comissions.Comission),
                Discount = comissions.Discount,
                IsComissionKeeped = comissions.IsComissionKeeped,
                IsFixed = comissions.IsFixed,
                Percent = comissions.Percent
            };
        }

        private static List<OssUniComissionDto> ConvertComission(List<OssUniComissionDeserializationDto> comission)
        {
            if (comission == null)
            {
                return null;
            }

            return comission.Select(x =>
                new OssUniComissionDto
                {
                    Cover = x.Cover,
                    Currency = x.Currency,
                    Sum = x.Sum
                })
                .ToList();
        }

        private static OssUniCompanyDto ConvertCompany(OssUniCompanyDeserializationDto company)
        {
            if (company == null)
            {
                return null;
            }

            return new OssUniCompanyDto
            {
                Name = company.Name,
                Inn = company.Inn,
                RegistrationCertificate = new OssUniRegistrationCertificateDto
                {
                    Type = company.RegistrationCertificate?.Type,
                    IssueDate = company.RegistrationCertificate?.IssueDate,
                    Number = company.RegistrationCertificate?.Number,
                    Serial = company.RegistrationCertificate?.Serial,
                    Paper = ConvertPaper(company.RegistrationCertificate?.Paper)
                }
            };
        }

        private static OssUniPaperDto ConvertPaper(OssUniPaperDeserializationDto paper)
        {
            if (paper == null)
            {
                return null;
            }

            return new OssUniPaperDto
            {
                DivisionCode = paper.DivisionCode,
                IssueDate = paper.IssueDate,
                IssuePlace = paper.IssuePlace,
                Number = paper.Number,
                PrevNumber = paper.PrevNumber,
                PrevSerial = paper.PrevSerial,
                PrevIssueDate = paper.PrevIssueDate,
                Serial = paper.Serial,
                Type = paper.Type
            };
        }

        private static OssUniPersonDto ConvertPerson(OssUniPersonDeserializationDto person)
        {
            if (person == null)
            {
                return null;
            }

            return new OssUniPersonDto
            {
                AllowedDate = person.AllowedDate,
                AllowedKvs = person.AllowedKvs,
                BirthDate = person.BirthDate,
                ClassBM = person.ClassBM,
                DriverCheckId = person.DriverCheckId,
                DrivingExperience = person.DrivingExperience,
                DrivingExperienceDate = person.DrivingExperienceDate,
                FirstName = person.FirstName,
                Ip = person.Ip,
                Kbm = person.Kbm,
                MaritalStatus = person.MaritalStatus,
                MiddleName = person.MiddleName,
                MinorChildren = person.MinorChildren,
                Papers = ConvertPapers(person.Papers),
                PersonAdditionalData = ConvertPersonAdditionalData(person.PersonAdditionalData),
                PrevFirstName = person.PrevFirstName,
                PrevMiddleName = person.PrevMiddleName,
                PrevSurname = person.PrevSurname,
                Sex = person.Sex,
                Snils = person.Snils,
                Surname = person.Surname
            };
        }

        private static List<OssUniPaperDto> ConvertPapers(List<OssUniPaperDeserializationDto> papers)
        {
            if (papers == null)
            {
                return null;
            }

            return papers.Select(x =>
                new OssUniPaperDto
                {
                    DivisionCode = x.DivisionCode,
                    IssueDate = x.IssueDate,
                    IssuePlace = x.IssuePlace,
                    Number = x.Number,
                    PrevNumber = x.PrevNumber,
                    PrevSerial = x.PrevSerial,
                    PrevIssueDate = x.PrevIssueDate,
                    Serial = x.Serial,
                    Type = x.Type
                })
                .ToList();
        }

        private static OssUniPersonAdditionalDataDto ConvertPersonAdditionalData(OssUniPersonAdditionalDataDeserializationDto personAdditionalData)
        {
            if (personAdditionalData == null)
            {
                return null;
            }

            return new OssUniPersonAdditionalDataDto
            {
                DateOfBirth = personAdditionalData.DateOfBirth,
                LastName = personAdditionalData.LastName,
                MiddleName = personAdditionalData.MiddleName,
                Name = personAdditionalData.Name
            };
        }

        private static OssUniRequisitesDto ConvertRequisites(OssUniRequisitesDeserializationDto requisites)
        {
            if (requisites == null)
            {
                return null;
            }

            return new OssUniRequisitesDto
            {
                Addresses = ConvertAddresses(requisites.Addresses),
                EMailList = ConvertEMailList(requisites.EMailList),
                PhoneList = ConvertPhoneList(requisites.PhoneList)
            };
        }

        private static List<OssUniAddressDto> ConvertAddresses(List<OssUniAddressDeserializationDto> addreddes)
        {
            if (addreddes == null)
            {
                return null;
            }

            return addreddes.Select(x =>
                new OssUniAddressDto
                {
                    Apartment = x.Apartment,
                    Building = x.Building,
                    City = x.City,
                    Construction = x.Construction,
                    Country = x.Country,
                    District = x.District,
                    FiasCode = x.FiasCode,
                    House = x.House,
                    KladrCode = x.KladrCode,
                    OkatoCode = x.OkatoCode,
                    Postcode = x.Postcode,
                    Region = x.Region,
                    Street = x.Street,
                    TextAddress = x.TextAddress,
                    Type = x.Type,
                    Township = x.Township,
                })
                .ToList();
        }

        private static List<OssUniEMailDto> ConvertEMailList(List<OssUniEMailDeserializationDto> eMailList)
        {
            if (eMailList == null)
            {
                return null;
            }

            return eMailList.Select(x =>
                new OssUniEMailDto
                {
                    Number = x.Number,
                    Type = x.Type
                })
                .ToList();
        }

        private static List<OssUniPhoneDto> ConvertPhoneList(List<OssUniPhoneDeserializationDto> phoneList)
        {
            if (phoneList == null)
            {
                return null;
            }

            return phoneList.Select(x =>
                new OssUniPhoneDto
                {
                    Number = x.Number,
                    Type = x.Type
                })
                .ToList();
        }

        private static OssUniRsaKbmDto ConvertRsaKbm(OssUniRsaKbmDeserializationDto rsaKbm)
        {
            if (rsaKbm == null)
            {
                return null;
            }

            return new OssUniRsaKbmDto
            {
                Bmclass = rsaKbm.Bmclass,
                CalcDate = rsaKbm.CalcDate,
                CalcId = rsaKbm.CalcId,
                Kbm = rsaKbm.Kbm
            };
        }

        private static OssUniPaymentsDto ConvertPayments(OssUniPaymentsDeserializationDto payments)
        {
            if (payments == null)
            {
                return null;
            }

            return new OssUniPaymentsDto
            {
                Payments = ConvertPayments(payments.Payments),
                PremiumPlan = payments.PremiumPlan
            };
        }

        private static List<OssUniPaymentDto> ConvertPayments(List<OssUniPaymentDeserializationDto> payments)
        {
            if (payments == null)
            {
                return null;
            }

            return payments.Select(x =>
                new OssUniPaymentDto
                {
                    Account = ConvertAccount(x.Account),
                    Amount = x.Amount,
                    PaymentDate = x.PaymentDate,
                    PaymentType = x.PaymentType,
                    PeriodNum = x.PeriodNum
                })
                .ToList();
        }

        private static OssUniAccountDto ConvertAccount(OssUniAccountDeserializationDto account)
        {
            if (account == null)
            {
                return null;
            }

            return new OssUniAccountDto
            {
                Bank = account.Bank,
                Bik = account.Bik,
                CorAccountNumber = account.CorAccountNumber,
                Currency = account.Currency,
                Inn = account.Inn,
                Number = account.Number,
                PersonalAccount = account.PersonalAccount
            };
        }

        private static List<OssUniPremiumDto> ConvertPremiumList(List<OssUniPremiumDeserializationDto> premiumList)
        {
            if (premiumList == null)
            {
                return null;
            }

            return premiumList.Select(x =>
                new OssUniPremiumDto
                {
                    CoeffMult = x.CoeffMult,
                    DateDiff = x.DateDiff,
                    Kc = x.Kc,
                    Kn = x.Kn,
                    Kt = x.Kt,
                    Number = x.Number,
                    StructId = x.StructId,
                    Tb = x.Tb
                })
                .ToList();
        }

        private static OssUniTelematicsDto ConvertTelematics(OssUniTelematicsDeserializationDto telematics)
        {
            if (telematics == null)
            {
                return null;
            }

            return new OssUniTelematicsDto
            {
                Number = telematics.Number,
                Installed = telematics.Installed,
                Mileagelimit = telematics.Mileagelimit,
                Type = telematics.Type
            };
        }

        private static OssUniVehicleDto ConvertVehicle(OssUniVehicleDeserializationDto vehicle)
        {
            if (vehicle == null)
            {
                return null;
            }

            return new OssUniVehicleDto
            {
                Autostart = vehicle.Autostart,
                BodyNum = vehicle.BodyNum,
                CarCode = vehicle.CarCode,
                CatCar = vehicle.CatCar,
                ChassisNum = vehicle.ChassisNum,
                Engine = ConvertEngine(vehicle.Engine),
                Examination = ConvertExamination(vehicle.Examination),
                FindSystems = ConvertFindSystems(vehicle.FindSystems),
                GuardSystem = vehicle.GuardSystem,
                KeyCount = vehicle.KeyCount,
                MaxWeight = vehicle.MaxWeight,
                MdmCarbodyType = vehicle.MdmCarbodyType,
                MdmKind = vehicle.MdmKind,
                MdmTransmissionType = vehicle.MdmTransmissionType,
                Mileage = vehicle.Mileage,
                Model = vehicle.Model,
                Price = vehicle.Price,
                RegistrationCertificate = ConvertRegistrationCertificate(vehicle.RegistrationCertificate),
                RegistrationNumber = vehicle.RegistrationNumber,
                RegistrationPlace = ConvertRegistrationPlace(vehicle.RegistrationPlace),
                ReleaseDate = vehicle.ReleaseDate,
                RsaCheckId = vehicle.RsaCheckId,
                SeatsNumber = vehicle.SeatsNumber,
                SplitMark = vehicle.SplitMark,
                SplitModel = vehicle.SplitModel,
                SplitModification = vehicle.SplitModification,
                SteeringWheelType = vehicle.SteeringWheelType,
                Usage = vehicle.Usage,
                UsageDate = vehicle.UsageDate,
                UsedInTaxi = vehicle.UsedInTaxi,
                UsedReason = vehicle.UsedReason,
                Vin = vehicle.Vin
            };
        }

        private static OssUniEngineDto ConvertEngine(OssUniEngineDeserializationDto engine)
        {
            if (engine == null)
            {
                return null;
            }

            return new OssUniEngineDto
            {
                EngineVolume = engine.EngineVolume,
                Hp = engine.Hp,
                MdmEngineType = engine.MdmEngineType
            };
        }

        private static OssUniExaminationDto ConvertExamination(OssUniExaminationDeserializationDto examination)
        {
            if (examination == null)
            {
                return null;
            }

            return new OssUniExaminationDto
            {
                Kind = examination.Kind,
                PsoChecked = examination.PsoChecked,
                Comment = examination.Comment,
                Date = examination.Date,
                ProxyNum = examination.ProxyNum
            };
        }

        private static List<OssUniFindSystemDto> ConvertFindSystems(List<OssUniFindSystemDeserializationDto> findSystems)
        {
            if (findSystems == null)
            {
                return null;
            }

            return findSystems.Select(x => new OssUniFindSystemDto
            {
                FindSystemMark = x.FindSystemMark,
                FindSystemModel = x.FindSystemModel,
                HiddenInstallation = x.HiddenInstallation
            }).ToList();
        }

        private static List<OssUniRegistrationCertificateDto> ConvertRegistrationCertificate(List<OssUniRegistrationCertificateDeserializationDto> registrationCertificates)
        {
            if (registrationCertificates == null)
            {
                return null;
            }

            return registrationCertificates.Select(x =>
                new OssUniRegistrationCertificateDto
                {
                    Number = x.Number,
                    IssueDate = x.IssueDate,
                    NextToDay = x.NextToDay,
                    NextToMonth = x.NextToMonth,
                    NextToYear = x.NextToYear,
                    Serial = x.Serial,
                    Type = x.Type
                })
                .ToList();
        }

        private static OssUniRegistrationPlaceDto ConvertRegistrationPlace(OssUniRegistrationPlaceDeserializationDto registrationPlace)
        {
            if (registrationPlace == null)
            {
                return null;
            }

            return new OssUniRegistrationPlaceDto { Region = registrationPlace.Region, City = registrationPlace.City };
        }
    }
}

using System;
using System.Linq;
using System.Threading.Tasks;
using iRIS.Framework.Workflow.Process.CustomProcessModel;
using iRIS.InsuranceCore.Entities;
using iRIS.InsuranceCore.Entities.EntityExtensions;
using iRIS.InsuranceCore.Entities.Enums;
using iRIS.InsuranceCore.OSS.Code;
using iRIS.InsuranceCore.OSS.Code.Dto;
using iRIS.InsuranceCore.OSS.Code.Mappers;
using iRIS.KaskoCore.CreateOn.Code.OssKaskoOptionsProcessor;
using iRIS.KaskoCore.CreateOn.Code.Utilities;
using iRIS.KaskoLink2.Code.CreateOn.Utilities;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using Serilog;

namespace iRIS.KaskoLink2.Modification.Code.CustomProcesses
{
    public class MapOssDataProcess : ICustomProcess, IAsyncCustomProcess
    {
        /// <summary>
        /// Корзина.
        /// </summary>
        public const string InputArgument_InputBasket = nameof(InputBasket);

        /// <summary>
        /// Корзина oss.
        /// </summary>
        public const string InputArgument_OssBasketUni = nameof(OssBasketUni);

        /// <summary>
        /// Корзина.
        /// </summary>
        public InputArgument<Basket> InputBasket { get; } = new InputArgument<Basket>(InputArgument_InputBasket);

        /// <summary>
        /// Корзина oss.
        /// </summary>
        /// <input/>
        public InputArgument<string> OssBasketUni { get; } = new InputArgument<string>(InputArgument_OssBasketUni);

        public void Execute(IProcessContext processContext)
        {
            ExecuteAsync(processContext).GetAwaiter().GetResult();
        }

        public async Task ExecuteAsync(IProcessContext processContext)
        {
            InputBasket.TryGet(processContext, out var basket);
            OssBasketUni.TryGet(processContext, out var ossBasketUni);

            var log = processContext.ServiceProvider.GetService<ILogger>().ForContext<MapOssDataProcess>();
            var mapperFactory = processContext.ServiceProvider.GetService<IOssMapperFactory>();

            try
            {
                var number = basket.Number;
                var deal = basket.GetKaskoDeal();
                var mapper = mapperFactory.Create(ProductDictCodes.Kasko);
                var uni = DtoConverter.Convert(OssUniDeserializer.DeserializeToPolicy(ossBasketUni));

                // Добавляем для маппинга в осс
                if (uni.Policy.SpecialTerm != null)
                {
                    deal.EntityContext.Add("prevSpecialTerm", uni.Policy.SpecialTerm);
                }
                
                uni.Policy.Participants?.ForEach(participant => participant.SiebelId = null);
               
                var agentParticipants = uni.Policy.Participants.Where(x => new[] { 2, 3, 10 }.Contains(x.Role)).ToList();
                if (uni.Policy.Participants != null && agentParticipants.Any())
                {
                    deal.EntityContext.Add("agentParticipants", agentParticipants);
                }

                if (uni.Policy.Channel != null)
                {
                    deal.EntityContext.Add("prevChannel", uni.Policy.Channel);
                }

                if (uni.Policy.Kasko.SpecialProgram != null)
                {
                    deal.EntityContext.Add("prevSpecialProgram", uni.Policy.Kasko.SpecialProgram);
                }

                deal.EntityContext.Add("signDate", uni.Policy.Date);

                var processor = processContext.ServiceProvider.GetRequiredService<IOssKaskoOptionsProcessor>();
                var parser = processContext.ServiceProvider.GetService<IOssKaskoOptionsParser>();
                var ossKaskoOptions = parser.Parse(uni.Policy);
                var ossKaskoOptionsExcept = ossKaskoOptions.Except(deal.AutoDeal.PreviousOssOptions, new OssKaskoOptionsComparer());

                deal.AutoDeal.PreviousOssOptions.AddRange(ossKaskoOptionsExcept);

                processor.SetOssKaskoOptions(basket);
                
                await mapper.MapToDealAsync(uni, basket);

                deal.IsEPolicy = true;
                basket.Number = number;
            }
            catch (Exception ex)
            {
                log.Error(ex, "Произошла ошибка при маппинге данных из ОСС");
                throw;
            }
        }
    }
}


Мне необходимо чтобы в классе MapOssDataProcess в обьекте uni было поле которого ранее не было - DateEnd обьекта payments, при этом я не могу изменять что то в классе DtoConverter. Помоги мне