<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Workflow\Compensation;

final class WorkflowCompensationStatistics
{
    public static function from(array $plans, array $requests, array $results): array
    {
        $successful = 0;
        foreach ($results as $result) {
            if (($result['successful'] ?? false) === true) {
                $successful++;
            }
        }

        $actions = 0;
        foreach ($plans as $plan) {
            $actions += count((array) ($plan['actions'] ?? []));
        }

        return [
            'plans' => count($plans),
            'actions' => $actions,
            'requests' => count($requests),
            'results' => count($results),
            'successfulResults' => $successful,
            'failedResults' => count($results) - $successful,
        ];
    }
}
