<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Scheduler;

final class SchedulerSnapshot
{
    public function __construct(private readonly array $events, private readonly string $createdAt = '') {}

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

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

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