package cloud.nstart.terravault.ordinis.cuod;

import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Триггерит {@link CuodBundleImporter#importBundle()} при старте Spring Boot.
 * Отделено от Importer в свой Configuration чтобы Importer оставался
 * proxified Spring service с работающим @Transactional.
 */
@Configuration
@ConditionalOnProperty(name = "ordinis.bundle.cuod.auto-import", havingValue = "true", matchIfMissing = false)
public class CuodBundleStartupRunner {

  @Bean
  @ConditionalOnBean(CuodBundleImporter.class)
  public ApplicationRunner cuodBundleImportRunner(CuodBundleImporter importer) {
    return args -> importer.importBundle();
  }
}
