class StackImageUpdateActions {

    @Bean(name = "CHECK_IMAGE_VERSIONS_STATE")
    public AbstractStackImageUpdateAction<?> checkImageVersion() {
        return new AbstractStackImageUpdateAction<>(StackImageUpdateTriggerEvent.class) {
            @Override
            protected void doExecute(StackContext context, StackImageUpdateTriggerEvent payload, Map<Object, Object> variables) {
                getFlowMessageService().fireEventAndLog(context.getStack().getId(), Status.UPDATE_IN_PROGRESS.name(), STACK_IMAGE_UPDATE_STARTED);
                if (!getStackImageUpdateService().isCbVersionOk(context.getStack())) {
                    throw new OperationException("Stack must be created at least with Cloudbreak version [" + StackImageUpdateService.MIN_VERSION + ']');
                }
                StatedImage newImage = getStackImageUpdateService().getNewImageIfVersionsMatch(context.getStack(), payload.getNewImageId(),
                        payload.getImageCatalogName(), payload.getImageCatalogUrl());
                sendEvent(context, new ImageUpdateEvent(StackImageUpdateEvent.CHECK_IMAGE_VERESIONS_FINISHED_EVENT.event(),
                        context.getStack().getId(), newImage));
            }
        };
    }

}