<?php
declare(strict_types=1);

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

final class DistributedFailoverSerializer
{
    public function encode(DistributedFailoverReport $report): string
    {
        return json_encode($report->toArray(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) ?: '{}';
    }

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