class CreateInitialStateWithVersionOrReplaceConfigurationAndExecuteCommand<T> implements RemoteCommand<T>, ComparableByContent<CreateInitialStateWithVersionOrReplaceConfigurationAndExecuteCommand> {

    private RemoteCommand<T> targetCommand;
    private BucketConfiguration configuration;
    private long desiredConfigurationVersion;
    private TokensInheritanceStrategy tokensInheritanceStrategy;

    public static SerializationHandle<CreateInitialStateWithVersionOrReplaceConfigurationAndExecuteCommand<?>> SERIALIZATION_HANDLE = new SerializationHandle<>() {
        @Override
        public <S> CreateInitialStateWithVersionOrReplaceConfigurationAndExecuteCommand<?> deserialize(DeserializationAdapter<S> adapter, S input) throws IOException {
            int formatNumber = adapter.readInt(input);
            Versions.check(formatNumber, v_8_1_0, v_8_1_0);

            BucketConfiguration configuration = BucketConfiguration.SERIALIZATION_HANDLE.deserialize(adapter, input);
            RemoteCommand<?> targetCommand = RemoteCommand.deserialize(adapter, input);
            long desiredConfigurationVersion = adapter.readLong(input);
            TokensInheritanceStrategy tokensInheritanceStrategy = TokensInheritanceStrategy.getById(adapter.readByte(input));

            return new CreateInitialStateWithVersionOrReplaceConfigurationAndExecuteCommand<>(configuration, targetCommand, desiredConfigurationVersion, tokensInheritanceStrategy);
        }

        @Override
        public <O> void serialize(SerializationAdapter<O> adapter, O output, CreateInitialStateWithVersionOrReplaceConfigurationAndExecuteCommand<?> command, Version backwardCompatibilityVersion, Scope scope) throws IOException {
            adapter.writeInt(output, v_8_1_0.getNumber());

            BucketConfiguration.SERIALIZATION_HANDLE.serialize(adapter, output, command.configuration, backwardCompatibilityVersion, scope);
            RemoteCommand.serialize(adapter, output, command.targetCommand, backwardCompatibilityVersion, scope);
            adapter.writeLong(output, command.desiredConfigurationVersion);
            adapter.writeByte(output, command.tokensInheritanceStrategy.getId());
        }

        @Override
        public int getTypeId() {
            return 41;
        }

        @Override
        public Class<CreateInitialStateWithVersionOrReplaceConfigurationAndExecuteCommand<?>> getSerializedType() {
            return (Class) CreateInitialStateWithVersionOrReplaceConfigurationAndExecuteCommand.class;
        }

        @Override
        public CreateInitialStateWithVersionOrReplaceConfigurationAndExecuteCommand<?> fromJsonCompatibleSnapshot(Map<String, Object> snapshot) throws IOException {
            int formatNumber = readIntValue(snapshot, "version");
            Versions.check(formatNumber, v_8_1_0, v_8_1_0);

            BucketConfiguration configuration = BucketConfiguration.SERIALIZATION_HANDLE
                    .fromJsonCompatibleSnapshot((Map<String, Object>) snapshot.get("configuration"));
            RemoteCommand<?> targetCommand = RemoteCommand.fromJsonCompatibleSnapshot((Map<String, Object>) snapshot.get("targetCommand"));
            TokensInheritanceStrategy tokensInheritanceStrategy = TokensInheritanceStrategy.valueOf((String) snapshot.get("tokensInheritanceStrategy"));
            long desiredConfigurationVersion = readLongValue(snapshot, "desiredConfigurationVersion");
            return new CreateInitialStateWithVersionOrReplaceConfigurationAndExecuteCommand<>(configuration, targetCommand, desiredConfigurationVersion, tokensInheritanceStrategy);
        }

        @Override
        public Map<String, Object> toJsonCompatibleSnapshot(CreateInitialStateWithVersionOrReplaceConfigurationAndExecuteCommand<?> command, Version backwardCompatibilityVersion, Scope scope) throws IOException {
            Map<String, Object> result = new HashMap<>();
            result.put("version", v_8_1_0.getNumber());
            result.put("configuration", BucketConfiguration.SERIALIZATION_HANDLE.toJsonCompatibleSnapshot(command.configuration, backwardCompatibilityVersion, scope));
            result.put("targetCommand", RemoteCommand.toJsonCompatibleSnapshot(command.targetCommand, backwardCompatibilityVersion, scope));
            result.put("desiredConfigurationVersion", command.desiredConfigurationVersion);
            result.put("tokensInheritanceStrategy", command.tokensInheritanceStrategy.toString());

            return result;
        }

        @Override
        public String getTypeName() {
            return "CreateInitialStateWithVersionOrReplaceConfigurationAndExecuteCommand";
        }

    };

    public CreateInitialStateWithVersionOrReplaceConfigurationAndExecuteCommand(BucketConfiguration configuration, RemoteCommand<T> targetCommand, long desiredConfigurationVersion, TokensInheritanceStrategy tokensInheritanceStrategy) {
        this.configuration = configuration;
        this.targetCommand = targetCommand;
        this.desiredConfigurationVersion = desiredConfigurationVersion;
        this.tokensInheritanceStrategy = tokensInheritanceStrategy;
    }

    @Override
    public CommandResult<T> execute(MutableBucketEntry mutableEntry, long currentTimeNanos) {<FILL_FUNCTION_BODY>}

    public BucketConfiguration getConfiguration() {
        return configuration;
    }

    public RemoteCommand<T> getTargetCommand() {
        return targetCommand;
    }

    public long getDesiredConfigurationVersion() {
        return desiredConfigurationVersion;
    }

    public TokensInheritanceStrategy getTokensInheritanceStrategy() {
        return tokensInheritanceStrategy;
    }

    @Override
    public boolean isInitializationCommand() {
        return true;
    }

    @Override
    public SerializationHandle getSerializationHandle() {
        return SERIALIZATION_HANDLE;
    }

    @Override
    public boolean equalsByContent(CreateInitialStateWithVersionOrReplaceConfigurationAndExecuteCommand other) {
        return ComparableByContent.equals(configuration, other.configuration) &&
                ComparableByContent.equals(targetCommand, other.targetCommand) &&
                desiredConfigurationVersion == other.desiredConfigurationVersion &&
                tokensInheritanceStrategy == other.tokensInheritanceStrategy;
    }

    @Override
    public boolean isImmediateSyncRequired(long unsynchronizedTokens, long nanosSinceLastSync) {
        return true;
    }

    @Override
    public long estimateTokensToConsume() {
        return targetCommand.estimateTokensToConsume();
    }

    @Override
    public long getConsumedTokens(T result) {
        return targetCommand.getConsumedTokens(result);
    }

    @Override
    public Version getRequiredVersion() {
        return Versions.max(v_8_1_0, targetCommand.getRequiredVersion());
    }

}

        if (mutableEntry.exists()) {
            RemoteBucketState state = mutableEntry.get();
            Long actualConfigurationVersion = state.getConfigurationVersion();
            if (actualConfigurationVersion == null || actualConfigurationVersion < desiredConfigurationVersion) {
                ReplaceConfigurationCommand replaceConfigurationCommand = new ReplaceConfigurationCommand(configuration, tokensInheritanceStrategy);
                replaceConfigurationCommand.execute(mutableEntry, currentTimeNanos);
                state.setConfigurationVersion(desiredConfigurationVersion);
            }
        } else {
            BucketState bucketState = BucketState.createInitialState(configuration, MathType.INTEGER_64_BITS, currentTimeNanos);
            RemoteBucketState state = new RemoteBucketState(bucketState, new RemoteStat(0), desiredConfigurationVersion);
            mutableEntry.set(state);
        }

        return targetCommand.execute(mutableEntry, currentTimeNanos);
    
<no_super_class>