<?php
declare(strict_types=1);

namespace Archive\Async1;

use App\Framework\Async1\TaskProcessor;

final class SynchronousTaskProcessor implements TaskProcessor
{
    /**
     * {@inheritdoc}
     */
    public function processTasks(array $tasks, mixed ...$sharedData): array
    {
        $results = [];

        foreach ($tasks as $index => $task) {
            try {
                $results[$index] = $task(...$sharedData);
            } catch (\Throwable $e) {
                error_log("Fehler bei Task #{$index}: " . $e->getMessage());
                $results[$index] = null;
            }
        }

        return $results;
    }

    /**
     * {@inheritdoc}
     */
    public static function isAvailable(): bool
    {
        return true; // Immer verfügbar
    }
}
