class DefaultAgentManagementService implements AgentManagementService {

    @Override
    public Completable updateInstanceGroupLifecycle(String instanceGroupId, InstanceGroupLifecycleStatus instanceGroupLifecycleStatus) {
        return agentCache.updateInstanceGroupStore(
                instanceGroupId,
                instanceGroup -> instanceGroup.toBuilder().withLifecycleStatus(instanceGroupLifecycleStatus).build()
        ).flatMapCompletable(instanceGroup -> {
            if (instanceGroupLifecycleStatus.getState() == InstanceGroupLifecycleState.Removable) {
                // Force the min to 0 when we change the state to Removable
                return internalUpdateCapacity(instanceGroup, Optional.of(0), Optional.empty());
            }
            return Completable.complete();
        });
    }

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

}