<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Streaming\Dlq;

final class StreamDlqSnapshot
{
    public function __construct(
        private readonly array $messages = [],
        private readonly array $results = [],
        private readonly array $statistics = [],
        private readonly array $policy = [],
        private readonly string $createdAt = ''
    ) {}

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

    public function messages(): array { return $this->messages; }
    public function results(): array { return $this->results; }
    public function statistics(): array { return $this->statistics; }

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