<?php
// app/config/database.php

/**
 * Database Configuration for CoreFlux Framework.
 *
 * This file defines the connection settings for your database.
 * It's recommended to use environment variables (.env) for sensitive credentials
 * in real-world applications to keep them out of version control.
 */

// Load .env variables if not already loaded (e.g., in bootstrap.php)
if (class_exists('Dotenv\Dotenv') && file_exists(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . '.env')) {
    $dotenv = Dotenv\Dotenv::createImmutable(dirname(dirname(dirname(__DIR__))));
    $dotenv->load();
}

return [
    // 'driver': The type of database driver to use.
    // CRITICAL FIX: The driver name for PDO is 'pdo_mysql', not just 'mysql'.
    'driver' => $_ENV['DB_DRIVER'] ?? 'mysql',

    // 'host': The database server host.
    'host' => $_ENV['DB_HOST'] ?? '127.0.0.1',

    // 'port': The database server port.
    'port' => $_ENV['DB_PORT'] ?? '3306',

    // 'database': The name of the database to connect to.
    'database' => $_ENV['DB_DATABASE'] ?? 'emergency_response_db',

    // 'username': The username for database access.
    'username' => $_ENV['DB_USERNAME'] ?? 'root',

    // 'password': The password for the database user.
    'password' => $_ENV['DB_PASSWORD'] ?? '',

    // 'charset': The character set to use for the database connection.
    'charset' => $_ENV['DB_CHARSET'] ?? 'utf8mb4',

    // 'collation': The collation to use for the database connection.
    'collation' => $_ENV['DB_COLLATION'] ?? 'utf8mb4_unicode_ci',

    // 'prefix': A table prefix, if you use one (e.g., 'cf_').
    'prefix' => $_ENV['DB_PREFIX'] ?? '',

    // 'strict': Enable strict mode for database queries.
    'strict' => $_ENV['DB_STRICT_MODE'] ?? true,

    // 'fetch_mode': How data should be fetched (e.g., PDO::FETCH_ASSOC for associative arrays).
    'fetch_mode' => PDO::FETCH_ASSOC,
];