package com.config;

import com.repository.*;
import com.repository.impl.*;
import com.service.*;
import com.service.impl.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;

/**
 *
 * Define bean configuration for DataSource, Repository and Service layers etc.
 *
 * @author Laurentiu Marcut
 */
@Configuration
@ComponentScan({ "com.repository", "com.service" })
@Import({ SpringSecurityConfig.class })
@EnableTransactionManagement
public class SpringRootConfig {

    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource ds = new DriverManagerDataSource();
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUrl("jdbc:mysql://aam43owqm7e0ir.cvgrpjtxfqoz.eu-central-1.rds.amazonaws.com:3306/ebdb");
        ds.setUsername("marcutl");
        ds.setPassword("Crazy4you");
        return ds;
    }

    @Bean
    public PlatformTransactionManager txManager() {
        return new DataSourceTransactionManager(this.dataSource());
    }

    @Bean
    public RegistrationRepository registrationRepository() {
        return new RegistrationRepositoryImpl();
    }

    @Bean
    public RegistrationService registrationService() {
        return new RegistrationServiceImpl();
    }

    @Bean
    public ProjectRepository projectRepository() {
        return new ProjectRepositoryImpl();
    }

    @Bean
    public ProjectService projectService() {
        return new ProjectServiceImpl();
    }

    @Bean
    public MemberProjectRepository memberProjectRepository() {
        return new MemberProjectRepositoryImpl();
    }

    @Bean
    public MemberProjectService memberProjectService() {
        return new MemberProjectServiceImpl();
    }

    @Bean
    public TaskRepository taskRepository() {
        return new TaskRepositoryImpl();
    }

    @Bean
    public TaskService taskService() {
        return new TaskServiceImpl();
    }

    @Bean
    public SprintsRepository sprintsRepository() {
        return new SprintsRepositoryImpl();
    }

    @Bean
    public SprintsService sprintsService() {
        return new SprintsServiceImpl();
    }
}
