from ....tl.mtproto_request import MTProtoRequest


class ToggleDialogPinRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messages.toggleDialogPin#3289be6a flags:# pinned:flags.0?true peer:InputPeer = Bool"""

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

    def __init__(self, peer, pinned=None):
        """
        :param pinned: Telegram type: «true».
        :param peer: Telegram type: «InputPeer».

        :returns Bool: This type has no constructors.
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.pinned = pinned
        self.peer = peer

    def on_send(self, writer):
        writer.write_int(ToggleDialogPinRequest.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 0) if self.pinned else 0
        writer.write_int(flags)

        self.peer.on_send(writer)

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

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

    def __repr__(self):
        return 'messages.toggleDialogPin#3289be6a flags:# pinned:flags.0?true peer:InputPeer = Bool'

    def __str__(self):
        return '(messages.toggleDialogPin (ID: 0x3289be6a) = (pinned={}, peer={}))'.format(str(self.pinned), str(self.peer))
