<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Workflow\Timer;

final class WorkflowTimerStatistics
{
    public static function from(array $timers, array $results): array
    {
        $scheduled = 0; $fired = 0; $cancelled = 0; $resultFired = 0;
        foreach ($timers as $timer) {
            $status = (string) ($timer['status'] ?? 'scheduled');
            if ($status === 'fired') { $fired++; } elseif ($status === 'cancelled') { $cancelled++; } else { $scheduled++; }
        }
        foreach ($results as $result) {
            if (($result['fired'] ?? false) === true) { $resultFired++; }
        }
        return ['timers' => count($timers), 'scheduled' => $scheduled, 'fired' => $fired, 'cancelled' => $cancelled, 'results' => count($results), 'firedResults' => $resultFired];
    }
}
