<?php

declare(strict_types=1);

namespace App\Framework\Notification\Channels\Telegram\Webhook;

/**
 * Telegram Message Value Object
 *
 * Represents an incoming message
 */
final readonly class TelegramMessage
{
    public function __construct(
        public int $messageId,
        public int $chatId,
        public string $text,
        public ?int $fromUserId = null,
        public ?string $fromUsername = null,
        public ?string $fromFirstName = null
    ) {
    }

    public static function fromArray(array $data): self
    {
        return new self(
            messageId: $data['message_id'],
            chatId: $data['chat']['id'],
            text: $data['text'] ?? '',
            fromUserId: $data['from']['id'] ?? null,
            fromUsername: $data['from']['username'] ?? null,
            fromFirstName: $data['from']['first_name'] ?? null
        );
    }
}
