from ...tl.mtproto_request import MTProtoRequest


class EncryptedMessage(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    encryptedMessage#ed18c118 random_id:long chat_id:int date:date bytes:bytes file:EncryptedFile = EncryptedMessage"""

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

    def __init__(self, random_id, chat_id, date, bytes, file):
        """
        :param random_id: Telegram type: «long».
        :param chat_id: Telegram type: «int».
        :param date: Telegram type: «date».
        :param bytes: Telegram type: «bytes».
        :param file: Telegram type: «EncryptedFile».

        Constructor for EncryptedMessage: Instance of either EncryptedMessage, EncryptedMessageService.
        """
        super().__init__()

        self.random_id = random_id
        self.chat_id = chat_id
        self.date = date
        self.bytes = bytes
        self.file = file

    def on_send(self, writer):
        writer.write_int(EncryptedMessage.constructor_id, signed=False)
        writer.write_long(self.random_id)
        writer.write_int(self.chat_id)
        writer.tgwrite_date(self.date)
        writer.tgwrite_bytes(self.bytes)
        self.file.on_send(writer)

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

    def on_response(self, reader):
        self.random_id = reader.read_long()
        self.chat_id = reader.read_int()
        self.date = reader.tgread_date()
        self.bytes = reader.tgread_bytes()
        self.file = reader.tgread_object()

    def __repr__(self):
        return 'encryptedMessage#ed18c118 random_id:long chat_id:int date:date bytes:bytes file:EncryptedFile = EncryptedMessage'

    def __str__(self):
        return '(encryptedMessage (ID: 0xed18c118) = (random_id={}, chat_id={}, date={}, bytes={}, file={}))'.format(str(self.random_id), str(self.chat_id), str(self.date), str(self.bytes), str(self.file))
