from telethon.tl.mtproto_request import MTProtoRequest


class GetTopPeersRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    contacts.getTopPeers#d4982db5 flags:None correspondents:flags.0?true bots_pm:flags.1?true bots_inline:flags.2?true groups:flags.10?true channels:flags.15?true offset:int limit:int hash:int = contacts.TopPeers"""

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

    def __init__(self, offset, limit, hash, correspondents=None, bots_pm=None, bots_inline=None, groups=None, channels=None):
        """
        :param correspondents: Telegram type: «true».
        :param bots_pm: Telegram type: «true».
        :param bots_inline: Telegram type: «true».
        :param groups: Telegram type: «true».
        :param channels: Telegram type: «true».
        :param offset: Telegram type: «int».
        :param limit: Telegram type: «int».
        :param hash: Telegram type: «int».
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.correspondents = correspondents
        self.bots_pm = bots_pm
        self.bots_inline = bots_inline
        self.groups = groups
        self.channels = channels
        self.offset = offset
        self.limit = limit
        self.hash = hash

    def on_send(self, writer):
        writer.write_int(GetTopPeersRequest.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 0) if self.correspondents else 0
        flags |= (1 << 1) if self.bots_pm else 0
        flags |= (1 << 2) if self.bots_inline else 0
        flags |= (1 << 10) if self.groups else 0
        flags |= (1 << 15) if self.channels else 0
        writer.write_int(flags)

        writer.write_int(self.offset)
        writer.write_int(self.limit)
        writer.write_int(self.hash)

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

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

    def __repr__(self):
        return 'contacts.getTopPeers#d4982db5 flags:None correspondents:flags.0?true bots_pm:flags.1?true bots_inline:flags.2?true groups:flags.10?true channels:flags.15?true offset:int limit:int hash:int = contacts.TopPeers'

    def __str__(self):
        return '(contacts.getTopPeers (ID: 0xd4982db5) = (correspondents={}, bots_pm={}, bots_inline={}, groups={}, channels={}, offset={}, limit={}, hash={}))'.format(str(self.correspondents), str(self.bots_pm), str(self.bots_inline), str(self.groups), str(self.channels), str(self.offset), str(self.limit), str(self.hash))
