<?php
/**
 * vendor/autoload.php
 *
 * BlackRed bundled autoloader.
 *
 * This file mimics Composer's vendor/autoload.php so the application code
 * doesn't have to care whether dependencies came from Composer or from this
 * bundled distribution.
 *
 * What's included in this bundle:
 *   - PSR-4 autoload for BlackRed\\ → src/
 *   - PSR-4 autoload for Dotenv\\  → vendor/dotenv/
 *   - PSR-4 autoload for Monolog\\ → vendor/monolog/
 *   - PSR-4 autoload for Ramsey\\Uuid\\ → vendor/uuid/
 *
 * If you later run `composer install`, this file is replaced by Composer's
 * generated autoloader and the bundled vendor/ subdirectories become
 * inactive (they remain on disk but PSR-4 mappings come from Composer).
 *
 * To replace this with real Composer dependencies:
 *   1. Delete vendor/autoload.php, vendor/dotenv/, vendor/monolog/, vendor/uuid/
 *   2. Run `composer install --no-dev --optimize-autoloader`
 *
 * The application code does not change — only the autoload source.
 */

declare(strict_types=1);

spl_autoload_register(function (string $class): bool {
    static $prefixes = null;
    if ($prefixes === null) {
        $prefixes = [
            'BlackRed\\' => __DIR__ . '/../src/',
            'Dotenv\\'   => __DIR__ . '/dotenv/',
            'Monolog\\'  => __DIR__ . '/monolog/',
        ];
    }

    foreach ($prefixes as $prefix => $baseDir) {
        if (str_starts_with($class, $prefix)) {
            $relative = substr($class, strlen($prefix));
            $path = $baseDir . str_replace('\\', '/', $relative) . '.php';
            if (is_file($path)) {
                require $path;
                return true;
            }
        }
    }
    return false;
});
