package dev.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DatabaseConnection {

    private static final String URL = getEnvOrDefault("DB_URL", "jdbc:postgresql://localhost:5432/postgres");
    private static final String USER = getEnvOrDefault("DB_USER", "postgres");
    private static final String PASSWORD = getEnvOrDefault("DB_PASSWORD", "password");

    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(URL, USER, PASSWORD);
    }

    private static String getEnvOrDefault(String key, String defaultValue) {
        String value = System.getenv(key);
        return (value != null && !value.isBlank()) ? value : defaultValue;
    }
}