protected function applyEvent(AggregateRootEventInterface $event, $auto_commit = true)
    {
        $this->guardEventPreConditions($event);
        if (!$this->setValues($event->getData())) {
            $errors = [];
            foreach ($this->getValidationResults() as $validation_result) {
                foreach ($validation_result->getViolatedRules() as $violated_rule) {
                    foreach ($violated_rule->getIncidents() as $incident) {
                        $errors[] = PHP_EOL . $validation_result->getSUbject()->getName() .
                            ' - ' . $violated_rule->getName() .
                            ' > ' . $incident->getName() . ': ' . print_r($incident->getParameters(), true);
                    }
                }
            }
            throw new InvalidStateError(
                sprintf(
                    "Aggregate-root is in an invalid state after applying %s.\nErrors:%s",
                    get_class($event),
                    implode(PHP_EOL, $errors)
                )
            );
        }

        $embedded_entity_events = new EmbeddedEntityEventList();
        foreach ($event->getEmbeddedEntityEvents() as $embedded_entity_event) {
            $embedded_entity_events->push($this->applyEmbeddedEntityEvent($embedded_entity_event));
        }

        $source_event = null;
        if ($auto_commit) {
            $recorded_changes = $this->getRecordedChanges();
            if (!empty($recorded_changes) || !$embedded_entity_events->isEmpty()) {
                $source_event = $event->createCopyWith(
                    [ 'data' => $recorded_changes, 'embedded_entity_events' => $embedded_entity_events ]
                );
                $this->uncomitted_events_list->push($source_event);
                $this->history->push($source_event);
            }
        } else {
            $source_event = $event;
        }

        if ($source_event) {
            $this->setValue('revision', $source_event->getSeqNumber());
            $this->markClean();
        } else {
            //$notice = 'Applied event %s for %s did not trigger any state changes, so it is being dropped ...';
            //error_log(sprintf($notice, $event, $this));
        }

        return $source_event;
    }