from ....tl.tlobject import TLObject
from ....utils import get_input_peer


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

    # Telegram's constructor (U)ID for this class
    constructor_id = 0x1c015b09
    # Also the ID of its resulting type for fast checks
    subclass_of_id = 0x2c49c116

    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.content_related = True

        self.just_clear = just_clear
        self.peer = get_input_peer(peer)
        self.max_id = max_id

    def to_dict(self):
        return {
            'just_clear': self.just_clear,
            'peer': None if self.peer is None else self.peer.to_dict(),
            'max_id': self.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 (attributes=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 TLObject.pretty_format(self)

    def stringify(self):
        return TLObject.pretty_format(self, indent=0)
