addType('id', 'integer'); $this->addType('botId', 'integer'); $this->addType('replyToMessageId', 'integer'); $this->addType('threadRootMessageId', 'integer'); $this->addType('attempts', 'integer'); $this->addType('priority', 'integer'); $this->addType('createdAt', 'integer'); $this->addType('processedAt', 'integer'); } /** * Check if request can be retried */ public function canRetry(int $maxAttempts = 3): bool { return $this->status === self::STATUS_FAILED && $this->attempts < $maxAttempts; } /** * Check if request is stale (older than given seconds) */ public function isStale(int $maxAgeSeconds = 3600): bool { return (time() - $this->createdAt) > $maxAgeSeconds; } /** * Increment attempt counter */ public function incrementAttempts(): void { $this->attempts++; } public function jsonSerialize(): array { return [ 'id' => $this->id, 'bot_id' => $this->botId, 'room_token' => $this->roomToken, 'user_id' => $this->userId, 'message' => $this->message, 'original_message' => $this->originalMessage, 'reply_to_message_id' => $this->replyToMessageId, 'thread_root_message_id' => $this->threadRootMessageId, 'status' => $this->status, 'result' => $this->result, 'error' => $this->error, 'attempts' => $this->attempts, 'priority' => $this->priority, 'created_at' => $this->createdAt, 'processed_at' => $this->processedAt, 'can_retry' => $this->canRetry(), 'is_stale' => $this->isStale(), ]; } }