<?php
// ===========================================================
// CONFIGURATION FILE (SAFE VERSION)
// Prevents duplicate function declaration errors
// ===========================================================

// ---- Helper functions ----
if (!function_exists('get_config')) {
    function get_config() {
        static $conf = null;
        if ($conf) return $conf;

        $conf = [
            // Database credentials
            'db' => [
                'host' => 'localhost',
                'name' => 'accountsbook_demodbb848',
                'user' => 'accountsbook_demousr84849',
                'pass' => '7]0-rWvsUW)n%i;*'
            ],

            // Amazon SES SMTP credentials
            'smtp' => [
                'host' => 'email-smtp.us-east-1.amazonaws.com',
                'port' => 587,
                'username' => 'AKIAWG5UMZF72YF7N5WE',
                'password' => 'BNRB9xxXnt/8K5+l1b0oPsP4KqSbuOGWy9vYBaA1zuIM',
                'secure' => 'tls'
            ],

            // From details (used in outgoing emails)
            'from' => [
                'email' => 'support@accounts-books.info',
                'name'  => 'Accounts Books'
            ],

            // Base URL of your app
            'base_url' => 'https://accounts-book.com/demo',

            // Secret key for unsubscribe and verification tokens
            'unsubscribe_secret' => 'change_this_secret_key'
        ];

        return $conf;
    }
}

// ---- Database Connection ----
if (!function_exists('get_pdo')) {
    function get_pdo() {
        $c = get_config();
        $db = $c['db'];
        $dsn = "mysql:host={$db['host']};dbname={$db['name']};charset=utf8mb4";

        try {
            $pdo = new PDO($dsn, $db['user'], $db['pass'], [
                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
            ]);
            return $pdo;
        } catch (PDOException $e) {
            die("Database connection failed: " . $e->getMessage());
        }
    }
}
?>
