<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Queue;

final class QueueSerializer
{
    public function serializeSnapshot(QueueSnapshot $snapshot): string
    {
        return json_encode($snapshot->toArray(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) ?: '{}';
    }

    public function deserializeSnapshot(string $json): QueueSnapshot
    {
        $data = json_decode($json, true);
        return QueueSnapshot::fromArray(is_array($data) ? $data : []);
    }
}
