<?php
declare(strict_types=1);
namespace PpPhp\Core\Platform\Event\Streaming\Replay;
final class StreamReplayRequest
{
    public function __construct(private readonly string $topic = '', private readonly int $fromSequence = 1, private readonly int $limit = 100, private readonly string $requestedBy = 'runtime') {}
    public static function create(string $topic = '', int $fromSequence = 1, int $limit = 100, string $requestedBy = 'runtime'): self { return new self($topic, max(1,$fromSequence), max(1,$limit), $requestedBy); }
    public static function fromArray(array $data): self { return new self((string)($data['topic']??''),(int)($data['fromSequence']??1),(int)($data['limit']??100),(string)($data['requestedBy']??'runtime')); }
    public function topic(): string { return $this->topic; } public function fromSequence(): int { return max(1,$this->fromSequence); } public function limit(): int { return max(1,$this->limit); }
    public function toArray(): array { return ['topic'=>$this->topic,'fromSequence'=>$this->fromSequence(),'limit'=>$this->limit(),'requestedBy'=>$this->requestedBy]; }
}
