<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Dispatcher\Persistence;

use PpPhp\Core\Platform\Event\Dispatcher\Runtime\DispatcherRuntimeState;

final class DispatcherStateRepository
{
    public function __construct(private readonly DispatcherStateStore $store) {}

    public function saveState(array $statistics, array $snapshot): DispatcherRuntimeState
    {
        return DispatcherRuntimeState::fromArray([
            'statistics' => $statistics,
            'snapshot' => $snapshot,
            'updatedAt' => date('c'),
        ]);
    }

    public function load(): DispatcherRuntimeState
    {
        return $this->store->load();
    }

    public function reset(): void
    {
        $this->store->reset();
    }
}
