<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Workflow\Engine;

final class WorkflowEngineStatistics
{
    public static function from(array $definitions, array $states, array $results): array
    {
        $running = 0; $completed = 0; $failed = 0; $successful = 0;
        foreach ($states as $state) {
            $status = (string) ($state['status'] ?? 'running');
            if ($status === 'completed') { $completed++; }
            elseif ($status === 'failed') { $failed++; }
            else { $running++; }
        }
        foreach ($results as $result) {
            if (($result['successful'] ?? false) === true) { $successful++; }
        }
        return [
            'definitions' => count($definitions),
            'states' => count($states),
            'running' => $running,
            'completed' => $completed,
            'failed' => $failed,
            'results' => count($results),
            'successfulResults' => $successful,
        ];
    }
}
