from ....tl.mtproto_request import MTProtoRequest


class GetDialogsRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messages.getDialogs#191ba9c5 flags:# exclude_pinned:flags.0?true offset_date:date offset_id:int offset_peer:InputPeer limit:int = messages.Dialogs"""

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

    def __init__(self, offset_date, offset_id, offset_peer, limit, exclude_pinned=None):
        """
        :param exclude_pinned: Telegram type: «true».
        :param offset_date: Telegram type: «date».
        :param offset_id: Telegram type: «int».
        :param offset_peer: Telegram type: «InputPeer».
        :param limit: Telegram type: «int».

        :returns messages.Dialogs: Instance of either Dialogs, DialogsSlice.
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.exclude_pinned = exclude_pinned
        self.offset_date = offset_date
        self.offset_id = offset_id
        self.offset_peer = offset_peer
        self.limit = limit

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

        writer.tgwrite_date(self.offset_date)
        writer.write_int(self.offset_id)
        self.offset_peer.on_send(writer)
        writer.write_int(self.limit)

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

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

    def __repr__(self):
        return 'messages.getDialogs#191ba9c5 flags:# exclude_pinned:flags.0?true offset_date:date offset_id:int offset_peer:InputPeer limit:int = messages.Dialogs'

    def __str__(self):
        return '(messages.getDialogs (ID: 0x191ba9c5) = (exclude_pinned={}, offset_date={}, offset_id={}, offset_peer={}, limit={}))'.format(str(self.exclude_pinned), str(self.offset_date), str(self.offset_id), str(self.offset_peer), str(self.limit))
