package f1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import f1.db.Database;
import jakarta.annotation.PostConstruct;

@SpringBootApplication
@Component
public class Main {
    public static String JDBC_URL;
    public static String JDBC_USER;
    public static String JDBC_PASSWORD;

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

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

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

    @PostConstruct
    public void init() {
        JDBC_URL = dbUrl;
        JDBC_USER = dbUsername;
        JDBC_PASSWORD = dbPassword;
    }

    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);
        var db = new Database(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
        db.init();
    }
}
