package ch.unisg.executorpool;

import java.util.concurrent.TimeUnit;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;

import ch.unisg.executorpool.adapter.out.persistence.mongodb.ExecutorRepository;
import ch.unisg.executorpool.application.port.out.LoadExecutorPort;
import ch.unisg.executorpool.domain.ExecutorPool;

@SpringBootApplication
@EnableMongoRepositories(basePackageClasses = ExecutorRepository.class)
public class ExecutorPoolApplication {

    @Autowired
    private LoadExecutorPort loadExecutorPort;

	public static void main(String[] args) {

        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

		SpringApplication.run(ExecutorPoolApplication.class, args);
	}

    @PostConstruct
    public void initializeExecutorPool() {
        // Is this allowed in main or does it need to be in a service?
        ExecutorPool.getExecutorPool().initExecutorPool(loadExecutorPort.loadAllExecutors());
    }

}
