<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Distributed\Failover;

use PpPhp\Core\Platform\Event\Distributed\DistributedRuntimeCoordinator;
use PpPhp\Core\Platform\Event\Distributed\Lease\DistributedLeaseManager;
use PpPhp\Core\Platform\Event\Distributed\Queue\DistributedQueueCoordinator;
use PpPhp\Core\Platform\Event\Distributed\Scheduler\DistributedScheduler;

final class DistributedClusterHealthManager
{
    public function __construct(private readonly string $basePath) {}

    public function summary(): array
    {
        $runtime = DistributedRuntimeCoordinator::instance($this->basePath)->summary();
        $leases = DistributedLeaseManager::instance($this->basePath)->summary();
        $queues = DistributedQueueCoordinator::instance($this->basePath)->summary();
        $scheduler = DistributedScheduler::instance($this->basePath)->summary();

        return [
            'workers' => $runtime['statistics'] ?? [],
            'leases' => $leases['statistics'] ?? [],
            'queues' => $queues['statistics'] ?? [],
            'scheduler' => $scheduler['statistics'] ?? [],
            'checkedAt' => date('c'),
        ];
    }
}
