from ....tl.mtproto_request import MTProtoRequest
from ....utils import get_input_peer
import os


class StartBotRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    messages.startBot#e6df7378 bot:InputUser peer:InputPeer random_id:long start_param:string = Updates"""

    # Telegram's constructor (U)ID for this class
    constructor_id = 0xe6df7378
    # Also the ID of its resulting type for fast checks
    subclass_of_id = 0x8af52aac

    def __init__(self, bot, peer, start_param, random_id=None):
        """
        :param bot: Telegram type: "InputUser".
        :param peer: Telegram type: "InputPeer".
        :param random_id: Telegram type: "long".
        :param start_param: Telegram type: "string".

        :returns Updates: Instance of either UpdatesTooLong, UpdateShortMessage, UpdateShortChatMessage, UpdateShort, UpdatesCombined, UpdatesTg, UpdateShortSentMessage.
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.bot = bot
        self.peer = get_input_peer(peer)
        self.random_id = random_id if random_id is not None else int.from_bytes(os.urandom(8), signed=True, byteorder='little')
        self.start_param = start_param

    def to_dict(self):
        return {
            'bot': None if self.bot is None else self.bot.to_dict(),
            'peer': None if self.peer is None else self.peer.to_dict(),
            'random_id': self.random_id,
            'start_param': self.start_param,
        }

    def on_send(self, writer):
        writer.write_int(StartBotRequest.constructor_id, signed=False)
        self.bot.on_send(writer)
        self.peer.on_send(writer)
        writer.write_long(self.random_id)
        writer.tgwrite_string(self.start_param)

    @staticmethod
    def empty():
        """Returns an "empty" instance (attributes=None)"""
        return StartBotRequest(None, None, None, None)

    def on_response(self, reader):
        self.result = reader.tgread_object()

    def __repr__(self):
        return 'messages.startBot#e6df7378 bot:InputUser peer:InputPeer random_id:long start_param:string = Updates'

    def __str__(self):
        return '(messages.startBot (ID: 0xe6df7378) = (bot={}, peer={}, random_id={}, start_param={}))'.format(str(self.bot), str(self.peer), str(self.random_id), str(self.start_param))
