private async Task <IEnumerable <DomainError> > BuildReservationValidationFailures(EditApprenticeshipValidationRequest request, Apprenticeship apprenticeship)
        {
            List <DomainError> errors = new List <DomainError>();

            if (request.StartDate.HasValue && !string.IsNullOrWhiteSpace(request.CourseCode))
            {
                var validationRequest = new ReservationValidationRequest(apprenticeship.ReservationId.Value, request.StartDate.Value, request.CourseCode);
                var validationResult  = await _reservationValidationService.Validate(validationRequest, CancellationToken.None);

                errors = validationResult.ValidationErrors.Select(error => new DomainError(error.PropertyName, error.Reason)).ToList();
            }

            return(errors);
        }
        private async Task ValidateReservation(DraftApprenticeshipDetails details, CancellationToken cancellationToken)
        {
            if (!details.ReservationId.HasValue || !details.StartDate.HasValue || details.TrainingProgramme == null)
            {
                return;
            }

            var validationRequest = new ReservationValidationRequest(details.ReservationId.Value, details.StartDate.Value, details.TrainingProgramme.CourseCode);

            var validationResult = await _reservationValidationService.Validate(validationRequest, cancellationToken);

            var errors = validationResult.ValidationErrors.Select(error => new DomainError(error.PropertyName, error.Reason)).ToList();

            errors.ThrowIfAny();
        }