class CloudbreakFlowService {

    public void saveLastCloudbreakFlowChainId(SdxCluster sdxCluster, FlowIdentifier flowIdentifier) {
        if (flowIdentifier == null) {
            LOGGER.info("Cloudbreak not sent flow identifier for cluster falling back to flow API.");
            trySaveLastCbFlowIdOrFlowChainId(sdxCluster);
        } else {
            LOGGER.info("Received cloudbreak flow identifier {} for cluster {}", flowIdentifier, sdxCluster.getClusterName());
            switch (flowIdentifier.getType()) {
                case FLOW:
                    setFlowIdAndResetFlowChainId(sdxCluster, flowIdentifier.getPollableId());
                    break;
                case FLOW_CHAIN:
                    setFlowChainIdAndResetFlowId(sdxCluster, flowIdentifier.getPollableId());
                    break;
                case NOT_TRIGGERED:
                    resetFlowIdAndFlowChainId(sdxCluster);
                    break;
                default:
                    throw new IllegalArgumentException("Unsupported flow type " + flowIdentifier.getType());
            }
            sdxClusterRepository.save(sdxCluster);
        }
    }

}