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


class CdnFile(TLObject):
    CONSTRUCTOR_ID = 0xa99fca4f
    SUBCLASS_OF_ID = 0xf5ccf928

    def __init__(self, bytes):
        """
        :param bytes bytes:

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

        self.bytes = bytes

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

    def to_bytes(self):
        return b''.join((
            b'O\xca\x9f\xa9',
            TLObject.serialize_bytes(self.bytes),
        ))

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

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

    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 bytes request_token:

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

        self.request_token = request_token

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

    def to_bytes(self):
        return b''.join((
            b'n\xe4\xa8\xee',
            TLObject.serialize_bytes(self.request_token),
        ))

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

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

    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 TLObject type:
        :param int mtime:
        :param bytes 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, recursive=True):
        return {
            'type': (None if self.type is None else self.type.to_dict()) if recursive else self.type,
            'mtime': self.mtime,
            'bytes': self.bytes,
        }

    def to_bytes(self):
        return b''.join((
            b'\xd5\x18j\t',
            self.type.to_bytes(),
            struct.pack('<i', self.mtime),
            TLObject.serialize_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 __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 int dc_id:
        :param bytes file_token:
        :param bytes encryption_key:
        :param bytes encryption_iv:
        :param list[TLObject] cdn_file_hashes:

        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, recursive=True):
        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]) if recursive else self.cdn_file_hashes,
        }

    def to_bytes(self):
        return b''.join((
            b'Z\xfeR\xea',
            struct.pack('<i', self.dc_id),
            TLObject.serialize_bytes(self.file_token),
            TLObject.serialize_bytes(self.encryption_key),
            TLObject.serialize_bytes(self.encryption_iv),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.cdn_file_hashes)),b''.join(x.to_bytes() for x in self.cdn_file_hashes),
        ))

    @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 __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 int size:
        :param str mime_type:
        :param TLObject file_type:
        :param int mtime:
        :param bytes 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, recursive=True):
        return {
            'size': self.size,
            'mime_type': self.mime_type,
            'file_type': (None if self.file_type is None else self.file_type.to_dict()) if recursive else self.file_type,
            'mtime': self.mtime,
            'bytes': self.bytes,
        }

    def to_bytes(self):
        return b''.join((
            b'\xbcS\xe7!',
            struct.pack('<i', self.size),
            TLObject.serialize_bytes(self.mime_type),
            self.file_type.to_bytes(),
            struct.pack('<i', self.mtime),
            TLObject.serialize_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 __str__(self):
        return TLObject.pretty_format(self)

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