<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Consumer;

final class QueueConsumerSnapshot
{
    public function __construct(
        private readonly array $statistics = [],
        private readonly array $queue = [],
        private readonly array $pool = [],
        private readonly string $createdAt = ''
    ) {}

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

    public function statistics(): array { return $this->statistics; }
    public function queue(): array { return $this->queue; }
    public function pool(): array { return $this->pool; }
    public function createdAt(): string { return $this->createdAt !== '' ? $this->createdAt : date('c'); }

    public function toArray(): array
    {
        return [
            'statistics' => $this->statistics,
            'queue' => $this->queue,
            'pool' => $this->pool,
            'createdAt' => $this->createdAt(),
        ];
    }
}
