from ...tl.tlobject import TLObject
import os


class EncryptedMessageService(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    encryptedMessageService#23734b06 random_id:long chat_id:int date:int bytes:bytes = EncryptedMessage"""

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

    def __init__(self, chat_id, date, bytes, random_id=None):
        """
        :param random_id: Telegram type: "long".
        :param chat_id: Telegram type: "int".
        :param date: Telegram type: "date".
        :param bytes: Telegram type: "bytes".

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

        self.random_id = random_id if random_id is not None else int.from_bytes(os.urandom(8), signed=True, byteorder='little')
        self.chat_id = chat_id
        self.date = date
        self.bytes = bytes

    def to_dict(self):
        return {
            'random_id': self.random_id,
            'chat_id': self.chat_id,
            'date': self.date,
            'bytes': self.bytes,
        }

    def on_send(self, writer):
        writer.write_int(EncryptedMessageService.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)

    @staticmethod
    def empty():
        """Returns an "empty" instance (attributes=None)"""
        return EncryptedMessageService(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()

    def __repr__(self):
        return 'encryptedMessageService#23734b06 random_id:long chat_id:int date:int bytes:bytes = EncryptedMessage'

    def __str__(self):
        return TLObject.pretty_format(self)

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