from ....tl.tlobject import TLObject


class FileCdnRedirect(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    upload.fileCdnRedirect#ea52fe5a dc_id:int file_token:bytes encryption_key:bytes encryption_iv:bytes cdn_file_hashes:Vector<CdnFileHash> = upload.File"""

    # Telegram's constructor (U)ID for this class
    constructor_id = 0xea52fe5a
    # Also the ID of its resulting type for fast checks
    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():
        """Returns an "empty" instance (attributes=None)"""
        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()  # Vector's constructor ID
        self.cdn_file_hashes = []  # Initialize an empty list
        _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)
