private function findOrNewRecord(array $recordsByHandle, array $definition, string $handle): Model
    {
        $record = new $definition['class']();
        if (array_key_exists($handle, $recordsByHandle)) {
            $existing = $recordsByHandle[$handle];
            if (get_class($record) == get_class($existing)) {
                $record = $existing;
            } else {
                $record->id = $existing->id;
                $record->setAttributes($existing->getAttributes());
            }
        }

        return $record;
    }