from telethon.tl.mtproto_request import MTProtoRequest


class UpdateDialogPinned(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    updateDialogPinned#d711a2cc flags:None pinned:flags.0?true peer:Peer = Update"""

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

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

        self.pinned = pinned
        self.peer = peer

    def on_send(self, writer):
        writer.write_int(UpdateDialogPinned.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 UpdateDialogPinned(None, None)

    def on_response(self, reader):
        flags = reader.read_int()

        if (flags & (1 << 0)) != 0:
            self.pinned = True  # Arbitrary not-None value, no need to read since it is a flag

        self.peer = reader.tgread_object()

    def __repr__(self):
        return 'updateDialogPinned#d711a2cc flags:None pinned:flags.0?true peer:Peer = Update'

    def __str__(self):
        return '(updateDialogPinned (ID: 0xd711a2cc) = (pinned={}, peer={}))'.format(str(self.pinned), str(self.peer))
