<?php

declare(strict_types=1);

namespace Install\Services;

final class InstallationReport
{
    /**
     * @param array<string,mixed> $audit
     *
     * @return array<string,mixed>
     */
    public function build(
        array $audit
    ): array {
        $groups = [];

        foreach (($audit['checks'] ?? []) as $check) {
            $group = (string)($check['group'] ?? 'Autres');
            $groups[$group][] = $check;
        }

        return [
            'ready' => (bool)($audit['ready'] ?? false),
            'groups' => $groups,
            'summary' => (array)($audit['summary'] ?? []),
            'sql' => (array)($audit['sql'] ?? []),
            'database_state' => (array)(
                $audit['database_state'] ?? []
            ),
            'blocking_failures' => (int)(
                $audit['blocking_failures'] ?? 0
            ),
            'warnings' => (int)(
                $audit['warnings'] ?? 0
            ),
        ];
    }
}
