"""File auto-generated by tglib TL generator. Do not edit manually."""
from ..tlobject import TLObject
from typing import Optional, List, Union
import os
import struct
from datetime import datetime


class CdnFile(TLObject):
    """TL type: upload.cdnFile"""
    CONSTRUCTOR_ID = 0xa99fca4f
    SUBCLASS_OF_ID = 0xf5ccf928

    def __init__(self, bytes: bytes):
        self.bytes = bytes

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

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(TLObject.serialize_bytes(self.bytes))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_bytes = reader.tgread_bytes()
        _args['bytes'] = _val_bytes
        return cls(**_args)


class CdnFileReuploadNeeded(TLObject):
    """TL type: upload.cdnFileReuploadNeeded"""
    CONSTRUCTOR_ID = 0xeea8e46e
    SUBCLASS_OF_ID = 0xf5ccf928

    def __init__(self, request_token: bytes):
        self.request_token = request_token

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

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(TLObject.serialize_bytes(self.request_token))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_request_token = reader.tgread_bytes()
        _args['request_token'] = _val_request_token
        return cls(**_args)


class File(TLObject):
    """TL type: upload.file"""
    CONSTRUCTOR_ID = 0x096a18d5
    SUBCLASS_OF_ID = 0x6c9bd728

    def __init__(self, type: 'TypeFileType', mtime: int, bytes: bytes):
        self.type = type
        self.mtime = mtime
        self.bytes = bytes

    def to_dict(self):
        return {
            '_': 'File',
            'type': self.type,
            'mtime': self.mtime,
            'bytes': self.bytes,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(bytes(self.type))
        buf.write(struct.pack('<i', self.mtime))
        buf.write(TLObject.serialize_bytes(self.bytes))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_type = reader.tgread_object()
        _args['type'] = _val_type
        _val_mtime = reader.read_int()
        _args['mtime'] = _val_mtime
        _val_bytes = reader.tgread_bytes()
        _args['bytes'] = _val_bytes
        return cls(**_args)


class FileCdnRedirect(TLObject):
    """TL type: upload.fileCdnRedirect"""
    CONSTRUCTOR_ID = 0xf18cda44
    SUBCLASS_OF_ID = 0x6c9bd728

    def __init__(self, dc_id: int, file_token: bytes, encryption_key: bytes, encryption_iv: bytes, file_hashes: List['TypeFileHash']):
        self.dc_id = dc_id
        self.file_token = file_token
        self.encryption_key = encryption_key
        self.encryption_iv = encryption_iv
        self.file_hashes = file_hashes

    def to_dict(self):
        return {
            '_': 'FileCdnRedirect',
            'dc_id': self.dc_id,
            'file_token': self.file_token,
            'encryption_key': self.encryption_key,
            'encryption_iv': self.encryption_iv,
            'file_hashes': self.file_hashes,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<i', self.dc_id))
        buf.write(TLObject.serialize_bytes(self.file_token))
        buf.write(TLObject.serialize_bytes(self.encryption_key))
        buf.write(TLObject.serialize_bytes(self.encryption_iv))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.file_hashes)))
        for item in self.file_hashes:
            buf.write(bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_dc_id = reader.read_int()
        _args['dc_id'] = _val_dc_id
        _val_file_token = reader.tgread_bytes()
        _args['file_token'] = _val_file_token
        _val_encryption_key = reader.tgread_bytes()
        _args['encryption_key'] = _val_encryption_key
        _val_encryption_iv = reader.tgread_bytes()
        _args['encryption_iv'] = _val_encryption_iv
        reader.read_int(signed=False)  # skip vector id
        _count_file_hashes = reader.read_int()
        _list_file_hashes = []
        for _ in range(_count_file_hashes):
            _item_file_hashes = reader.tgread_object()
            _list_file_hashes.append(_item_file_hashes)
        _args['file_hashes'] = _list_file_hashes
        return cls(**_args)


class WebFile(TLObject):
    """TL type: upload.webFile"""
    CONSTRUCTOR_ID = 0x21e753bc
    SUBCLASS_OF_ID = 0x68f17f51

    def __init__(self, size: int, mime_type: str, file_type: 'TypeFileType', mtime: int, bytes: bytes):
        self.size = size
        self.mime_type = mime_type
        self.file_type = file_type
        self.mtime = mtime
        self.bytes = bytes

    def to_dict(self):
        return {
            '_': 'WebFile',
            'size': self.size,
            'mime_type': self.mime_type,
            'file_type': self.file_type,
            'mtime': self.mtime,
            'bytes': self.bytes,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<i', self.size))
        buf.write(TLObject.serialize_bytes(self.mime_type))
        buf.write(bytes(self.file_type))
        buf.write(struct.pack('<i', self.mtime))
        buf.write(TLObject.serialize_bytes(self.bytes))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_size = reader.read_int()
        _args['size'] = _val_size
        _val_mime_type = reader.tgread_string()
        _args['mime_type'] = _val_mime_type
        _val_file_type = reader.tgread_object()
        _args['file_type'] = _val_file_type
        _val_mtime = reader.read_int()
        _args['mtime'] = _val_mtime
        _val_bytes = reader.tgread_bytes()
        _args['bytes'] = _val_bytes
        return cls(**_args)

