<?php
/**
 * Database Configuration Class
 * 
 * Loads database credentials from .env file
 * Uses base64 encoding for compatibility with existing DB.php class
 * 
 * @author ESDN Development Team
 * @version 2.0.0
 */

require_once __DIR__ . '/EnvLoader.php';

class DBU
{

    static $view_user = array();
    static $dba_user = array();

    /**
     * Initialize database configuration from .env
     */
    public static function init()
    {
        // Load credentials from .env
        $host = EnvLoader::get('DB_HOST', 'localhost');
        $database = EnvLoader::get('DB_DATABASE', '');
        $username = EnvLoader::get('DB_USERNAME', '');
        $password = EnvLoader::get('DB_PASSWORD', '');

        // Encode credentials (for compatibility with existing DB.php)
        self::$view_user = array(
            'user' => base64_encode($username),
            'key' => base64_encode($password),
            'host' => base64_encode($host),
            'db' => base64_encode($database)
        );

        self::$dba_user = array(
            'user' => base64_encode($username),
            'key' => base64_encode($password),
            'host' => base64_encode($host),
            'db' => base64_encode($database)
        );
    }
}

// Auto-initialize on load
DBU::init();

// CREATE USER 'madrasa'@'localhost' IDENTIFIED WITH mysql_native_password BY '$@fxHdl0*c_3O;';
// GRANT ALL PRIVILEGES ON `madrasa_db_new`.* TO 'madrasa'@'localhost';
// GRANT ALL PRIVILEGES ON *.* TO 'madrasa'@'localhost';
// FLUSH PRIVILEGES;
