public function save(TransactionInterface $transaction = null, bool $queueRelations = true): int
    {
        /*
         * First, per interface agreement calculate entity state after save command being called.
         */
        if (!$this->isLoaded()) {
            $state = self::CREATED;
        } elseif (!$this->hasChanges()) {
            $state = self::UPDATED;
        } else {
            $state = self::UNCHANGED;
        }

        if (empty($transaction)) {
            /*
             * When no transaction is given we will create our own and run it immediately.
             */
            $transaction = $transaction ?? new Transaction();
            $transaction->store($this, $queueRelations);
            $transaction->run();
        } else {
            $transaction->addCommand($this->queueStore($queueRelations));
        }

        return $state;
    }