<?php

declare(strict_types=1);

namespace App\Framework\CommandBus\Middleware;

use App\Framework\CommandBus\Middleware;
use App\Framework\Logging\Logger;

final readonly class LoggingMiddleware implements Middleware
{
    public function __construct(
        private Logger $logger
    ) {
    }

    public function handle(object $command, callable $next): mixed
    {
        $commandClass = get_class($command);
        $this->logger->info("Starting command: $commandClass");

        $result = $next($command);

        $this->logger->info("Finished command: $commandClass");

        return $result;
    }
}
