from ...tl.mtproto_request import MTProtoRequest


class KeyboardButtonRow(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    keyboardButtonRow#77608b83 buttons:Vector<KeyboardButton> = KeyboardButtonRow"""

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

    def __init__(self, buttons):
        """
        :param buttons: Telegram type: «KeyboardButton». Must be a list.

        Constructor for KeyboardButtonRow: Instance of KeyboardButtonRow.
        """
        super().__init__()

        self.buttons = buttons

    def on_send(self, writer):
        writer.write_int(KeyboardButtonRow.constructor_id, signed=False)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.buttons))
        for buttons_item in self.buttons:
            buttons_item.on_send(writer)

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

    def on_response(self, reader):
        reader.read_int()  # Vector's constructor ID
        self.buttons = []  # Initialize an empty list
        buttons_len = reader.read_int()
        for _ in range(buttons_len):
            buttons_item = reader.tgread_object()
            self.buttons.append(buttons_item)

    def __repr__(self):
        return 'keyboardButtonRow#77608b83 buttons:Vector<KeyboardButton> = KeyboardButtonRow'

    def __str__(self):
        return '(keyboardButtonRow (ID: 0x77608b83) = (buttons={}))'.format(None if not self.buttons else [str(_) for _ in self.buttons])
