from ....tl.mtproto_request import MTProtoRequest


class DeleteHistoryRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messages.deleteHistory#1c015b09 flags:# just_clear:flags.0?true peer:InputPeer max_id:int = messages.AffectedHistory"""

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

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

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

        self.just_clear = just_clear
        self.peer = peer
        self.max_id = max_id

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

        self.peer.on_send(writer)
        writer.write_int(self.max_id)

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

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

    def __repr__(self):
        return 'messages.deleteHistory#1c015b09 flags:# just_clear:flags.0?true peer:InputPeer max_id:int = messages.AffectedHistory'

    def __str__(self):
        return '(messages.deleteHistory (ID: 0x1c015b09) = (just_clear={}, peer={}, max_id={}))'.format(str(self.just_clear), str(self.peer), str(self.max_id))
