public string GetValidationErrors(MessageSendArgument argument)
        {
            var errors = new List <string>();

            if (argument.DocumentType == null)
            {
                errors.Add("Тип документа не может быть пустым");
            }
            else
            {
                if (argument.DocumentType.UID <= 0)
                {
                    errors.Add("Некорректный тип документа");
                }
            }

            if (_validationHelper.FileIsEmpty(argument.File, argument))
            {
                errors.Add("Не добавлен файл!");
            }

            if (!_validationHelper.FileNameIsCorrect(argument.File, argument))
            {
                errors.Add("Не корректное имя файла!");
            }
            else
            {
                if (!_validationHelper.CheckFileExtension(new[] { ".pdf" }, argument.File, argument))
                {
                    errors.Add("Файл должен быть в формате \".pdf\"");
                }
            }
            if (errors.Count == 0)
            {
                return(null);
            }
            return(string.Join(Environment.NewLine, errors.ToArray()));
        }
        public string GetValidationErrors(RequisitionSendArgument argument)
        {
            if (argument.PatentType == null)
            {
                return("Не указан ExternalPatentType!");
            }

            var errors = new List <string>();

            if (string.IsNullOrEmpty(argument.AdrCustomerName))
            {
                errors.Add("AdrCustomerName не указан!");
            }

            if (argument.AdrCountry == null)
            {
                errors.Add("AdrCountry не указан!");
            }

            if (argument.AdrStreet == null)
            {
                errors.Add("AdrStreet не указан!");
            }

            if (argument.AdrEmail == null)
            {
                errors.Add("AdrEmail не указан!");
            }

            var applicants = 0;
            var attorney   = 0;
            var authors    = 0;
            var errRefKey  = false;
            var errCusType = false;

            foreach (var customer in argument.BlockCustomer)
            {
                if (customer.PatentLinkType == null)
                {
                    errRefKey = true;
                }
                else
                {
                    switch (customer.PatentLinkType.UID)
                    {
                    case 1:
                        applicants++;
                        break;

                    case 479:
                    case 4:
                        attorney++;
                        break;

                    case 2:
                        authors++;
                        break;
                    }
                }

                if (customer.Type == null)
                {
                    errCusType = true;
                }
            }

            if (errRefKey)
            {
                errors.Add("BlockCustomer: Customer.PatentLinkType не указан!");
            }

            if (errCusType)
            {
                errors.Add("BlockCustomer: Customer.Type не указан!");
            }

            if (applicants <= 0)
            {
                errors.Add("Нужно добавить как минимум одного заявителя!");
            }
            else
            {
                var cusType = GetErrApplicatTypeForPatentType(argument.PatentType.UID, argument.BlockCustomer);
                if (!string.IsNullOrEmpty(cusType))
                {
                    errors.Add("Для заявки ExternalPatentType.UID = " + argument.PatentType.UID +
                               ", заявитель не может быть BlockCustomer: Customer.Type.UID = " + cusType);
                }
            }


            var dicProtectionDocTypeCode =
                _dictionaryHelper.GetDictionaryCodeByExternalId(nameof(DicProtectionDocType), argument.PatentType.UID);

            if (dicProtectionDocTypeCode == DicProtectionDocType.Codes.Trademark)
            {
                if (argument.BlockClassification.Length <= 0)
                {
                    errors.Add("Нужно указать как минимум один МКТУ!");
                }
            }

            if (authors <= 0 && (
                    dicProtectionDocTypeCode == DicProtectionDocType.Codes.Invention ||
                    dicProtectionDocTypeCode == DicProtectionDocType.Codes.IndustrialModel ||
                    dicProtectionDocTypeCode == DicProtectionDocType.Codes.UsefulModel ||
                    dicProtectionDocTypeCode == DicProtectionDocType.Codes.SelectiveAchievement
                    ))
            {
                errors.Add("Нужно добавить как минимум одного автора!");
            }

            var patentLinkType  = false;
            var customerType    = false;
            var errCustomerName = false;

            foreach (var customer in argument.BlockCustomer)
            {
                if (customer.PatentLinkType == null)
                {
                    patentLinkType = true;
                }

                if (customer.Type == null)
                {
                    customerType = true;
                }

                if (string.IsNullOrEmpty(customer.NameRu))
                {
                    errCustomerName = true;
                }
            }

            if (errCustomerName)
            {
                errors.Add("Не указан ФИО/Полное наименование на русском языке BlockCustomer: Customer.NameRu");
            }

            if (patentLinkType)
            {
                errors.Add("Не указан тип связки контрагента BlockCustomer: Customer.PatentLinkType");
            }

            if (customerType)
            {
                errors.Add("Не указан тип контрагента BlockCustomer: Customer.Type");
            }

            if (!patentLinkType && !customerType)
            {
                errors.AddRange(GetArgumentErrorRequisitionSendAttachedFiles(argument, argument));
            }

            if (!_validationHelper.SenderIsPep(argument.SystemInfo.Sender) &&
                _validationHelper.FileIsEmpty(argument.RequisitionFile, argument))
            {
                errors.Add("RequisitionFile. Заявление не может быть пустым");
            }

            if (_validationHelper.SenderIsPep(argument.SystemInfo.Sender) && argument.RequisitionFile != null)
            {
                errors.Add("ПЭП должен отправлять RequisitionFile = null");
            }

            if (_validationHelper.SenderIsPep(argument.SystemInfo.Sender) && argument.RequisitionFile == null)
            {
                argument.RequisitionFile = new File {
                    Name = argument.SystemInfo.ChainId + ".pdf"
                };

                try
                {
                    argument.RequisitionFile.Content =
                        _attachFileHelper.DownloadPepRequisitionFile(argument.SystemInfo.ChainId, argument.Xin);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, ex.Message);
                    errors.Add("Не удалось получить pdf файл заявки. Заявка " + argument.SystemInfo.ChainId);
                    errors.Add(ex.Message);
                }
            }

            if (argument.RequisitionFile != null && argument.RequisitionFile.Content != null)
            {
                if (argument.RequisitionFile.Content.Length < 10)
                {
                    errors.Add("Файл заявки пуст. Заявка " + argument.SystemInfo.ChainId);
                }
                else
                {
                    const string textPdf  = "%PDF";
                    var          textFile = Encoding.UTF8.GetString(argument.RequisitionFile.Content, 0, 4);

                    if (textFile != textPdf)
                    {
                        errors.Add("Файл заявки не является PDF-документом. Заявка " + argument.SystemInfo.ChainId);
                    }
                }
            }

            if (errors.Count == 0)
            {
                return(null);
            }

            return(string.Join(Environment.NewLine, errors.ToArray()));
        }