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


class GetCdnFileRequest(TLRequest):
    """TL type: upload.getCdnFile"""
    CONSTRUCTOR_ID = 0x395f69da
    SUBCLASS_OF_ID = 0xf5ccf928

    def __init__(self, file_token: bytes, offset: int, limit: int):
        self.file_token = file_token
        self.offset = offset
        self.limit = limit

    def to_dict(self):
        return {
            '_': 'GetCdnFileRequest',
            'file_token': self.file_token,
            'offset': self.offset,
            'limit': self.limit,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_file_token = reader.tgread_bytes()
        _args['file_token'] = _val_file_token
        _val_offset = reader.read_long()
        _args['offset'] = _val_offset
        _val_limit = reader.read_int()
        _args['limit'] = _val_limit
        return cls(**_args)


class GetCdnFileHashesRequest(TLRequest):
    """TL type: upload.getCdnFileHashes"""
    CONSTRUCTOR_ID = 0x91dc3f31
    SUBCLASS_OF_ID = 0xa5940726

    def __init__(self, file_token: bytes, offset: int):
        self.file_token = file_token
        self.offset = offset

    def to_dict(self):
        return {
            '_': 'GetCdnFileHashesRequest',
            'file_token': self.file_token,
            'offset': self.offset,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_file_token = reader.tgread_bytes()
        _args['file_token'] = _val_file_token
        _val_offset = reader.read_long()
        _args['offset'] = _val_offset
        return cls(**_args)


class GetFileRequest(TLRequest):
    """TL type: upload.getFile"""
    CONSTRUCTOR_ID = 0xbe5335be
    SUBCLASS_OF_ID = 0x6c9bd728

    def __init__(self, location: 'TypeInputFileLocation', offset: int, limit: int, precise: Optional[bool] = None, cdn_supported: Optional[bool] = None):
        self.location = location
        self.offset = offset
        self.limit = limit
        self.precise = precise
        self.cdn_supported = cdn_supported

    def to_dict(self):
        return {
            '_': 'GetFileRequest',
            'location': self.location,
            'offset': self.offset,
            'limit': self.limit,
            'precise': self.precise,
            'cdn_supported': self.cdn_supported,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        flags = 0
        if self.precise:
            flags |= (1 << 0)
        if self.cdn_supported:
            flags |= (1 << 1)
        buf.write(struct.pack('<I', flags))
        buf.write(bytes(self.location))
        buf.write(struct.pack('<q', self.offset))
        buf.write(struct.pack('<i', self.limit))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        flags = reader.read_int(signed=False)
        _args['precise'] = bool(flags & (1 << 0))
        _args['cdn_supported'] = bool(flags & (1 << 1))
        _val_location = reader.tgread_object()
        _args['location'] = _val_location
        _val_offset = reader.read_long()
        _args['offset'] = _val_offset
        _val_limit = reader.read_int()
        _args['limit'] = _val_limit
        return cls(**_args)


class GetFileHashesRequest(TLRequest):
    """TL type: upload.getFileHashes"""
    CONSTRUCTOR_ID = 0x9156982a
    SUBCLASS_OF_ID = 0xa5940726

    def __init__(self, location: 'TypeInputFileLocation', offset: int):
        self.location = location
        self.offset = offset

    def to_dict(self):
        return {
            '_': 'GetFileHashesRequest',
            'location': self.location,
            'offset': self.offset,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_location = reader.tgread_object()
        _args['location'] = _val_location
        _val_offset = reader.read_long()
        _args['offset'] = _val_offset
        return cls(**_args)


class GetWebFileRequest(TLRequest):
    """TL type: upload.getWebFile"""
    CONSTRUCTOR_ID = 0x24e6818d
    SUBCLASS_OF_ID = 0x68f17f51

    def __init__(self, location: 'TypeInputWebFileLocation', offset: int, limit: int):
        self.location = location
        self.offset = offset
        self.limit = limit

    def to_dict(self):
        return {
            '_': 'GetWebFileRequest',
            'location': self.location,
            'offset': self.offset,
            'limit': self.limit,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_location = reader.tgread_object()
        _args['location'] = _val_location
        _val_offset = reader.read_int()
        _args['offset'] = _val_offset
        _val_limit = reader.read_int()
        _args['limit'] = _val_limit
        return cls(**_args)


class ReuploadCdnFileRequest(TLRequest):
    """TL type: upload.reuploadCdnFile"""
    CONSTRUCTOR_ID = 0x9b2754a8
    SUBCLASS_OF_ID = 0xa5940726

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

    def to_dict(self):
        return {
            '_': 'ReuploadCdnFileRequest',
            'file_token': self.file_token,
            '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.file_token))
        buf.write(TLObject.serialize_bytes(self.request_token))
        return buf.getvalue()

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


class SaveBigFilePartRequest(TLRequest):
    """TL type: upload.saveBigFilePart"""
    CONSTRUCTOR_ID = 0xde7b673d
    SUBCLASS_OF_ID = 0xf5b399ac

    def __init__(self, file_id: int, file_part: int, file_total_parts: int, bytes: bytes):
        self.file_id = file_id
        self.file_part = file_part
        self.file_total_parts = file_total_parts
        self.bytes = bytes

    def to_dict(self):
        return {
            '_': 'SaveBigFilePartRequest',
            'file_id': self.file_id,
            'file_part': self.file_part,
            'file_total_parts': self.file_total_parts,
            'bytes': self.bytes,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_file_id = reader.read_long()
        _args['file_id'] = _val_file_id
        _val_file_part = reader.read_int()
        _args['file_part'] = _val_file_part
        _val_file_total_parts = reader.read_int()
        _args['file_total_parts'] = _val_file_total_parts
        _val_bytes = reader.tgread_bytes()
        _args['bytes'] = _val_bytes
        return cls(**_args)


class SaveFilePartRequest(TLRequest):
    """TL type: upload.saveFilePart"""
    CONSTRUCTOR_ID = 0xb304a621
    SUBCLASS_OF_ID = 0xf5b399ac

    def __init__(self, file_id: int, file_part: int, bytes: bytes):
        self.file_id = file_id
        self.file_part = file_part
        self.bytes = bytes

    def to_dict(self):
        return {
            '_': 'SaveFilePartRequest',
            'file_id': self.file_id,
            'file_part': self.file_part,
            'bytes': self.bytes,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_file_id = reader.read_long()
        _args['file_id'] = _val_file_id
        _val_file_part = reader.read_int()
        _args['file_part'] = _val_file_part
        _val_bytes = reader.tgread_bytes()
        _args['bytes'] = _val_bytes
        return cls(**_args)

