<?php

class Database {
    private $host;
    private $db_name;
    private $username;
    private $password;
    public $conn;

    public function __construct() {
        require_once __DIR__ . '/SystemSettings.php';

        $config = require __DIR__ . '/../config/database.php';
        $this->host = $config['host'];
        $this->db_name = $config['db_name'];
        $this->username = $config['username'];
        $this->password = $config['password'];
    }

    public function getConnection() {
        $this->conn = null;

        try {
            $this->conn = new PDO("mysql:host={$this->host};dbname={$this->db_name}", $this->username, $this->password);
            $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            (new SystemSettings(null, $this->conn))->all();
        } catch (PDOException $e) {
            error_log("Database connection error: " . $e->getMessage());
        }

        return $this->conn;
    }
}
?>
