package ovh.herisson.Clyde;

import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.scheduling.annotation.EnableScheduling;

@Configuration
@EnableScheduling
public class JdbcConfig {

	@Bean
	@Profile("!prod")
	public DataSource psqlSource(){
		DriverManagerDataSource source = new DriverManagerDataSource();
		source.setDriverClassName("org.postgresql.Driver");
		source.setUrl("jdbc:postgresql://localhost:5432/clyde");
		source.setUsername("devel");
		source.setPassword("devel");

		return source;
	}

	@Bean
	@Profile("prod")
	public DataSource psqlSourceProd(){
		DriverManagerDataSource source = new DriverManagerDataSource();
		source.setDriverClassName("org.postgresql.Driver");
		source.setUrl("jdbc:postgresql:clyde?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg&socketFactoryArg=/var/run/postgresql/.s.PGSQL.5432");
		source.setUsername("clyde");

		return source;
	}
}
