from ....tl.mtproto_request import MTProtoRequest
import os


class SendEncryptedFileRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    messages.sendEncryptedFile#9a901b66 peer:InputEncryptedChat random_id:long data:bytes file:InputEncryptedFile = messages.SentEncryptedMessage"""

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

    def __init__(self, peer, data, file, random_id=None):
        """
        :param peer: Telegram type: "InputEncryptedChat".
        :param random_id: Telegram type: "long".
        :param data: Telegram type: "bytes".
        :param file: Telegram type: "InputEncryptedFile".

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

        self.peer = peer
        self.random_id = random_id if random_id is not None else int.from_bytes(os.urandom(8), signed=True, byteorder='little')
        self.data = data
        self.file = file

    def to_dict(self):
        return {
            'peer': None if self.peer is None else self.peer.to_dict(),
            'random_id': self.random_id,
            'data': self.data,
            'file': None if self.file is None else self.file.to_dict(),
        }

    def on_send(self, writer):
        writer.write_int(SendEncryptedFileRequest.constructor_id, signed=False)
        self.peer.on_send(writer)
        writer.write_long(self.random_id)
        writer.tgwrite_bytes(self.data)
        self.file.on_send(writer)

    @staticmethod
    def empty():
        """Returns an "empty" instance (attributes=None)"""
        return SendEncryptedFileRequest(None, None, None, None)

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

    def __repr__(self):
        return 'messages.sendEncryptedFile#9a901b66 peer:InputEncryptedChat random_id:long data:bytes file:InputEncryptedFile = messages.SentEncryptedMessage'

    def __str__(self):
        return '(messages.sendEncryptedFile (ID: 0x9a901b66) = (peer={}, random_id={}, data={}, file={}))'.format(str(self.peer), str(self.random_id), str(self.data), str(self.file))
