<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Distributed;

final class DistributedRuntimeReportWriter
{
    public function write(string $basePath, array $verification): string
    {
        $reportDir = rtrim($basePath, DIRECTORY_SEPARATOR) . '/storage/reports/r0100';

        if (!is_dir($reportDir)) {
            mkdir($reportDir, 0775, true);
        }

        $reportFile = $reportDir . '/r0100-distributed-runtime-full-report.json';

        file_put_contents($reportFile, json_encode([
            'milestone' => 'R0100.5E.6.6',
            'name' => 'Distributed Runtime Full Verification',
            'generatedAt' => date('c'),
            'verification' => $verification,
        ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));

        return $reportFile;
    }
}
