package f1;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import f1.db.*;

@Configuration
public class AppConfig {

    @Value("${spring.datasource.url}")
    private String dbUrl;

    @Value("${spring.datasource.username}")
    private String dbUsername;

    @Value("${spring.datasource.password}")
    private String dbPassword;

    @Bean
    public Database database() {
        Database db = new Database(dbUrl, dbUsername, dbPassword);
        db.init();
        return db;
    }

    @Bean
    public UserDao userDao(Database db) {
        return new UserDao(db);
    }

    @Bean
    public DriverDao driverDao(Database db) {
        return new DriverDao(db);
    }

    @Bean
    public TeamDao teamDao(Database db) {
        return new TeamDao(db);
    }

    @Bean
    public RaceDao raceDao(Database db) {
        return new RaceDao(db);
    }
}
