class DefaultAgentManagementService implements AgentManagementService {

    @Override
    public Completable updateCapacity(String instanceGroupId, Optional<Integer> min, Optional<Integer> desired) {
        if (!configuration.isInstanceGroupUpdateCapacityEnabled()) {
            return Completable.complete();
        }
        return Observable.fromCallable(() -> agentCache.getInstanceGroup(instanceGroupId))
                .flatMap(instanceGroup -> {
                            if (instanceGroup.getLifecycleStatus().getState() == InstanceGroupLifecycleState.Removable && min.isPresent()) {
                                return Observable.error(AgentManagementException.invalidArgument("Min cannot be set in the Removable state"));
                            }
                            return internalUpdateCapacity(instanceGroup, min, desired).toObservable();
                        }
                )
                .toCompletable();
    }

    @Inject public  DefaultAgentManagementService(AgentManagementConfiguration configuration,
                                         @Named(KUBE_SCHEDULER_INSTANCE_GROUP_PREDICATE) Predicate<AgentInstanceGroup> kubeSchedulerInstanceGroupPredicate,
                                         InstanceCloudConnector instanceCloudConnector,
                                         AgentCache AgentCache,
                                         ServerInfoResolver serverInfoResolver,
                                         TitusRuntime titusRuntime);

}