"""File generated by TLObjects' generator. All changes will be ERASED"""
from ...tl.tlobject import TLObject


class CdnFile(TLObject):
    constructor_id = 0xa99fca4f
    subclass_of_id = 0xf5ccf928

    def __init__(self, bytes):
        """
        :param bytes: Telegram type: "bytes".

        Constructor for upload.CdnFile: Instance of either CdnFileReuploadNeeded, CdnFile.
        """
        super().__init__()

        self.bytes = bytes

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

    def on_send(self, writer):
        writer.write_int(CdnFile.constructor_id, signed=False)
        writer.tgwrite_bytes(self.bytes)

    @staticmethod
    def empty():
        return CdnFile(None)

    def on_response(self, reader):
        self.bytes = reader.tgread_bytes()

    def __repr__(self):
        return 'upload.cdnFile#a99fca4f bytes:bytes = upload.CdnFile'

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

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



class CdnFileReuploadNeeded(TLObject):
    constructor_id = 0xeea8e46e
    subclass_of_id = 0xf5ccf928

    def __init__(self, request_token):
        """
        :param request_token: Telegram type: "bytes".

        Constructor for upload.CdnFile: Instance of either CdnFileReuploadNeeded, CdnFile.
        """
        super().__init__()

        self.request_token = request_token

    def to_dict(self):
        return {
            'request_token': self.request_token,
        }

    def on_send(self, writer):
        writer.write_int(CdnFileReuploadNeeded.constructor_id, signed=False)
        writer.tgwrite_bytes(self.request_token)

    @staticmethod
    def empty():
        return CdnFileReuploadNeeded(None)

    def on_response(self, reader):
        self.request_token = reader.tgread_bytes()

    def __repr__(self):
        return 'upload.cdnFileReuploadNeeded#eea8e46e request_token:bytes = upload.CdnFile'

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

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



class File(TLObject):
    constructor_id = 0x96a18d5
    subclass_of_id = 0x6c9bd728

    def __init__(self, type, mtime, bytes):
        """
        :param type: Telegram type: "storage.FileType".
        :param mtime: Telegram type: "int".
        :param bytes: Telegram type: "bytes".

        Constructor for upload.File: Instance of either File, FileCdnRedirect.
        """
        super().__init__()

        self.type = type
        self.mtime = mtime
        self.bytes = bytes

    def to_dict(self):
        return {
            'type': None if self.type is None else self.type.to_dict(),
            'mtime': self.mtime,
            'bytes': self.bytes,
        }

    def on_send(self, writer):
        writer.write_int(File.constructor_id, signed=False)
        self.type.on_send(writer)
        writer.write_int(self.mtime)
        writer.tgwrite_bytes(self.bytes)

    @staticmethod
    def empty():
        return File(None, None, None)

    def on_response(self, reader):
        self.type = reader.tgread_object()
        self.mtime = reader.read_int()
        self.bytes = reader.tgread_bytes()

    def __repr__(self):
        return 'upload.file#096a18d5 type:storage.FileType mtime:int bytes:bytes = upload.File'

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

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



class FileCdnRedirect(TLObject):
    constructor_id = 0xea52fe5a
    subclass_of_id = 0x6c9bd728

    def __init__(self, dc_id, file_token, encryption_key, encryption_iv, cdn_file_hashes):
        """
        :param dc_id: Telegram type: "int".
        :param file_token: Telegram type: "bytes".
        :param encryption_key: Telegram type: "bytes".
        :param encryption_iv: Telegram type: "bytes".
        :param cdn_file_hashes: Telegram type: "CdnFileHash". Must be a list.

        Constructor for upload.File: Instance of either File, FileCdnRedirect.
        """
        super().__init__()

        self.dc_id = dc_id
        self.file_token = file_token
        self.encryption_key = encryption_key
        self.encryption_iv = encryption_iv
        self.cdn_file_hashes = cdn_file_hashes

    def to_dict(self):
        return {
            'dc_id': self.dc_id,
            'file_token': self.file_token,
            'encryption_key': self.encryption_key,
            'encryption_iv': self.encryption_iv,
            'cdn_file_hashes': [] if self.cdn_file_hashes is None else [None if x is None else x.to_dict() for x in self.cdn_file_hashes],
        }

    def on_send(self, writer):
        writer.write_int(FileCdnRedirect.constructor_id, signed=False)
        writer.write_int(self.dc_id)
        writer.tgwrite_bytes(self.file_token)
        writer.tgwrite_bytes(self.encryption_key)
        writer.tgwrite_bytes(self.encryption_iv)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.cdn_file_hashes))
        for _x in self.cdn_file_hashes:
            _x.on_send(writer)

    @staticmethod
    def empty():
        return FileCdnRedirect(None, None, None, None, None)

    def on_response(self, reader):
        self.dc_id = reader.read_int()
        self.file_token = reader.tgread_bytes()
        self.encryption_key = reader.tgread_bytes()
        self.encryption_iv = reader.tgread_bytes()
        reader.read_int()
        self.cdn_file_hashes = []
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.cdn_file_hashes.append(_x)

    def __repr__(self):
        return 'upload.fileCdnRedirect#ea52fe5a dc_id:int file_token:bytes encryption_key:bytes encryption_iv:bytes cdn_file_hashes:Vector<CdnFileHash> = upload.File'

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

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



class WebFile(TLObject):
    constructor_id = 0x21e753bc
    subclass_of_id = 0x68f17f51

    def __init__(self, size, mime_type, file_type, mtime, bytes):
        """
        :param size: Telegram type: "int".
        :param mime_type: Telegram type: "string".
        :param file_type: Telegram type: "storage.FileType".
        :param mtime: Telegram type: "int".
        :param bytes: Telegram type: "bytes".

        Constructor for upload.WebFile: Instance of WebFile.
        """
        super().__init__()

        self.size = size
        self.mime_type = mime_type
        self.file_type = file_type
        self.mtime = mtime
        self.bytes = bytes

    def to_dict(self):
        return {
            'size': self.size,
            'mime_type': self.mime_type,
            'file_type': None if self.file_type is None else self.file_type.to_dict(),
            'mtime': self.mtime,
            'bytes': self.bytes,
        }

    def on_send(self, writer):
        writer.write_int(WebFile.constructor_id, signed=False)
        writer.write_int(self.size)
        writer.tgwrite_string(self.mime_type)
        self.file_type.on_send(writer)
        writer.write_int(self.mtime)
        writer.tgwrite_bytes(self.bytes)

    @staticmethod
    def empty():
        return WebFile(None, None, None, None, None)

    def on_response(self, reader):
        self.size = reader.read_int()
        self.mime_type = reader.tgread_string()
        self.file_type = reader.tgread_object()
        self.mtime = reader.read_int()
        self.bytes = reader.tgread_bytes()

    def __repr__(self):
        return 'upload.webFile#21e753bc size:int mime_type:string file_type:storage.FileType mtime:int bytes:bytes = upload.WebFile'

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

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

