from telethon.tl.mtproto_request import MTProtoRequest


class BotInfo(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    botInfo#98e81d3a user_id:int description:string commands:Vector<BotCommand> = BotInfo"""

    # Telegram's constructor ID (and unique identifier) for this class
    constructor_id = 0x98e81d3a

    def __init__(self, user_id, description, commands):
        """
        :param user_id: Telegram type: «int».
        :param description: Telegram type: «string».
        :param commands: Telegram type: «BotCommand». Must be a list.
        """
        super().__init__()

        self.user_id = user_id
        self.description = description
        self.commands = commands

    def on_send(self, writer):
        writer.write_int(BotInfo.constructor_id, signed=False)
        writer.write_int(self.user_id)
        writer.tgwrite_string(self.description)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.commands))
        for commands_item in self.commands:
            commands_item.on_send(writer)

    @staticmethod
    def empty():
        """Returns an "empty" instance (all attributes are None)"""
        return BotInfo(None, None, None)

    def on_response(self, reader):
        self.user_id = reader.read_int()
        self.description = reader.tgread_string()
        reader.read_int()  # Vector's constructor ID
        self.commands = []  # Initialize an empty list
        commands_len = reader.read_int()
        for _ in range(commands_len):
            commands_item = reader.tgread_object()
            self.commands.append(commands_item)

    def __repr__(self):
        return 'botInfo#98e81d3a user_id:int description:string commands:Vector<BotCommand> = BotInfo'

    def __str__(self):
        return '(botInfo (ID: 0x98e81d3a) = (user_id={}, description={}, commands={}))'.format(str(self.user_id), str(self.description), None if not self.commands else [str(_) for _ in self.commands])
