<?php

namespace App\Framework\Logging;

use App\Framework\Core\PathProvider;
use App\Framework\Database\DatabaseManager;
use App\Framework\DI\Initializer;
use App\Framework\Logging\Handlers\ConsoleHandler;
use App\Framework\Logging\Handlers\FileHandler;
use App\Framework\Logging\Handlers\QueuedLogHandler;
use App\Framework\Logging\Handlers\WebHandler;
use App\Framework\Queue\FileQueue;
use App\Framework\Queue\Queue;
use App\Framework\Queue\RedisQueue;

;

final readonly class LoggerInitializer
{
    public function __construct(
        #private DatabaseManager $db,
        #private PathProvider $pathProvider,
    ){}

    #[Initializer]
    public function __invoke():Logger
    {
        $processorManager = new ProcessorManager();

        $queue = new RedisQueue('commands', 'redis');
        #$path = $this->pathProvider->resolvePath('/src/Framework/CommandBus/storage/queue');
        #$queue = new FileQueue($path);

        return new DefaultLogger(
                    minLevel: LogLevel::DEBUG,
                    handlers: [
                        new QueuedLogHandler($queue),
                        new ConsoleHandler(),
                        new WebHandler(),
                        new FileHandler('logs/app.log')],
                    processorManager: $processorManager,
        );
    }
}
