<?php
declare(strict_types=1);

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

final class DistributedQueueSnapshot
{
    public function __construct(
        private readonly array $queues = [],
        private readonly array $partitions = [],
        private readonly array $statistics = [],
        private readonly string $createdAt = ''
    ) {}

    public static function fromArray(array $data): self
    {
        return new self(
            (array) ($data['queues'] ?? []),
            (array) ($data['partitions'] ?? []),
            (array) ($data['statistics'] ?? []),
            (string) ($data['createdAt'] ?? '')
        );
    }

    public function queues(): array { return $this->queues; }
    public function partitions(): array { return $this->partitions; }
    public function statistics(): array { return $this->statistics; }

    public function toArray(): array
    {
        return [
            'queues' => $this->queues,
            'partitions' => $this->partitions,
            'statistics' => $this->statistics,
            'createdAt' => $this->createdAt !== '' ? $this->createdAt : date('c'),
        ];
    }
}
