package com.style24.front.support.startup;

import java.io.IOException;
import java.util.Arrays;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import com.style24.core.support.env.TscConstants;

import lombok.extern.slf4j.Slf4j;

import com.gagaframework.web.core.GagaConstants;

/**
 * Application
 * @author gagamel
 * @since 2020. 9. 11
 */
@EnableCaching
@Configuration
@EnableAutoConfiguration(exclude = {DataSourceTransactionManagerAutoConfiguration.class, DataSourceAutoConfiguration.class})
@ComponentScan(basePackages = {GagaConstants.GAGA_PACKAGE, TscConstants.BASE_PACKAGE})
@Slf4j
public class TsfApplication {

	@Autowired
	private Environment env;

	@PostConstruct
	public void initApplication() throws IOException {
		log.info("Running with Spring Profiles: {}", Arrays.toString(env.getActiveProfiles()));
		if (env.getActiveProfiles().length == 0) {
			log.warn("No spring profile configured, running with default configuration.");
		} else if (env.getActiveProfiles().length > 1) {
			log.error("You have misconfigured your application! It should not run with both Spring Profiles at the same time.");
		}
	}

	public static void main(String[] args) {
		SpringApplication.run(TsfApplication.class, args);
	}

}
