"""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 InitConnectionRequest(TLRequest):
    """TL type: initConnection"""
    CONSTRUCTOR_ID = 0xc1cd5ea9
    SUBCLASS_OF_ID = 0xb7b2364b

    def __init__(self, api_id: int, device_model: str, system_version: str, app_version: str, system_lang_code: str, lang_pack: str, lang_code: str, query: 'TypeX', proxy: Optional['TypeInputClientProxy'] = None, params: Optional['TypeJSONValue'] = None):
        self.api_id = api_id
        self.device_model = device_model
        self.system_version = system_version
        self.app_version = app_version
        self.system_lang_code = system_lang_code
        self.lang_pack = lang_pack
        self.lang_code = lang_code
        self.query = query
        self.proxy = proxy
        self.params = params

    def to_dict(self):
        return {
            '_': 'InitConnectionRequest',
            'api_id': self.api_id,
            'device_model': self.device_model,
            'system_version': self.system_version,
            'app_version': self.app_version,
            'system_lang_code': self.system_lang_code,
            'lang_pack': self.lang_pack,
            'lang_code': self.lang_code,
            'query': self.query,
            'proxy': self.proxy,
            'params': self.params,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        flags = 0
        if self.proxy is not None:
            flags |= (1 << 0)
        if self.params is not None:
            flags |= (1 << 1)
        buf.write(struct.pack('<I', flags))
        buf.write(struct.pack('<i', self.api_id))
        buf.write(TLObject.serialize_bytes(self.device_model))
        buf.write(TLObject.serialize_bytes(self.system_version))
        buf.write(TLObject.serialize_bytes(self.app_version))
        buf.write(TLObject.serialize_bytes(self.system_lang_code))
        buf.write(TLObject.serialize_bytes(self.lang_pack))
        buf.write(TLObject.serialize_bytes(self.lang_code))
        buf.write(bytes(self.query))
        if self.proxy is not None:
            buf.write(bytes(self.proxy))
        if self.params is not None:
            buf.write(bytes(self.params))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        flags = reader.read_int(signed=False)
        _val_api_id = reader.read_int()
        _args['api_id'] = _val_api_id
        _val_device_model = reader.tgread_string()
        _args['device_model'] = _val_device_model
        _val_system_version = reader.tgread_string()
        _args['system_version'] = _val_system_version
        _val_app_version = reader.tgread_string()
        _args['app_version'] = _val_app_version
        _val_system_lang_code = reader.tgread_string()
        _args['system_lang_code'] = _val_system_lang_code
        _val_lang_pack = reader.tgread_string()
        _args['lang_pack'] = _val_lang_pack
        _val_lang_code = reader.tgread_string()
        _args['lang_code'] = _val_lang_code
        if flags & (1 << 0):
            _val_proxy = reader.tgread_object()
            _args['proxy'] = _val_proxy
        else:
            _args['proxy'] = None
        if flags & (1 << 1):
            _val_params = reader.tgread_object()
            _args['params'] = _val_params
        else:
            _args['params'] = None
        _val_query = reader.tgread_object()
        _args['query'] = _val_query
        return cls(**_args)


class InvokeAfterMsgRequest(TLRequest):
    """TL type: invokeAfterMsg"""
    CONSTRUCTOR_ID = 0xcb9f372d
    SUBCLASS_OF_ID = 0xb7b2364b

    def __init__(self, msg_id: int, query: 'TypeX'):
        self.msg_id = msg_id
        self.query = query

    def to_dict(self):
        return {
            '_': 'InvokeAfterMsgRequest',
            'msg_id': self.msg_id,
            'query': self.query,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_msg_id = reader.read_long()
        _args['msg_id'] = _val_msg_id
        _val_query = reader.tgread_object()
        _args['query'] = _val_query
        return cls(**_args)


class InvokeAfterMsgsRequest(TLRequest):
    """TL type: invokeAfterMsgs"""
    CONSTRUCTOR_ID = 0x3dc4b4f0
    SUBCLASS_OF_ID = 0xb7b2364b

    def __init__(self, msg_ids: List[int], query: 'TypeX'):
        self.msg_ids = msg_ids
        self.query = query

    def to_dict(self):
        return {
            '_': 'InvokeAfterMsgsRequest',
            'msg_ids': self.msg_ids,
            'query': self.query,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.msg_ids)))
        for item in self.msg_ids:
            buf.write(struct.pack('<q', self.item))
        buf.write(bytes(self.query))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        reader.read_int(signed=False)  # skip vector id
        _count_msg_ids = reader.read_int()
        _list_msg_ids = []
        for _ in range(_count_msg_ids):
            _item_msg_ids = reader.read_long()
            _list_msg_ids.append(_item_msg_ids)
        _args['msg_ids'] = _list_msg_ids
        _val_query = reader.tgread_object()
        _args['query'] = _val_query
        return cls(**_args)


class InvokeWithApnsSecretRequest(TLRequest):
    """TL type: invokeWithApnsSecret"""
    CONSTRUCTOR_ID = 0x0dae54f8
    SUBCLASS_OF_ID = 0xb7b2364b

    def __init__(self, nonce: str, secret: str, query: 'TypeX'):
        self.nonce = nonce
        self.secret = secret
        self.query = query

    def to_dict(self):
        return {
            '_': 'InvokeWithApnsSecretRequest',
            'nonce': self.nonce,
            'secret': self.secret,
            'query': self.query,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_nonce = reader.tgread_string()
        _args['nonce'] = _val_nonce
        _val_secret = reader.tgread_string()
        _args['secret'] = _val_secret
        _val_query = reader.tgread_object()
        _args['query'] = _val_query
        return cls(**_args)


class InvokeWithBusinessConnectionRequest(TLRequest):
    """TL type: invokeWithBusinessConnection"""
    CONSTRUCTOR_ID = 0xdd289f8e
    SUBCLASS_OF_ID = 0xb7b2364b

    def __init__(self, connection_id: str, query: 'TypeX'):
        self.connection_id = connection_id
        self.query = query

    def to_dict(self):
        return {
            '_': 'InvokeWithBusinessConnectionRequest',
            'connection_id': self.connection_id,
            'query': self.query,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_connection_id = reader.tgread_string()
        _args['connection_id'] = _val_connection_id
        _val_query = reader.tgread_object()
        _args['query'] = _val_query
        return cls(**_args)


class InvokeWithGooglePlayIntegrityRequest(TLRequest):
    """TL type: invokeWithGooglePlayIntegrity"""
    CONSTRUCTOR_ID = 0x1df92984
    SUBCLASS_OF_ID = 0xb7b2364b

    def __init__(self, nonce: str, token: str, query: 'TypeX'):
        self.nonce = nonce
        self.token = token
        self.query = query

    def to_dict(self):
        return {
            '_': 'InvokeWithGooglePlayIntegrityRequest',
            'nonce': self.nonce,
            'token': self.token,
            'query': self.query,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_nonce = reader.tgread_string()
        _args['nonce'] = _val_nonce
        _val_token = reader.tgread_string()
        _args['token'] = _val_token
        _val_query = reader.tgread_object()
        _args['query'] = _val_query
        return cls(**_args)


class InvokeWithLayerRequest(TLRequest):
    """TL type: invokeWithLayer"""
    CONSTRUCTOR_ID = 0xda9b0d0d
    SUBCLASS_OF_ID = 0xb7b2364b

    def __init__(self, layer: int, query: 'TypeX'):
        self.layer = layer
        self.query = query

    def to_dict(self):
        return {
            '_': 'InvokeWithLayerRequest',
            'layer': self.layer,
            'query': self.query,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_layer = reader.read_int()
        _args['layer'] = _val_layer
        _val_query = reader.tgread_object()
        _args['query'] = _val_query
        return cls(**_args)


class InvokeWithMessagesRangeRequest(TLRequest):
    """TL type: invokeWithMessagesRange"""
    CONSTRUCTOR_ID = 0x365275f2
    SUBCLASS_OF_ID = 0xb7b2364b

    def __init__(self, range: 'TypeMessageRange', query: 'TypeX'):
        self.range = range
        self.query = query

    def to_dict(self):
        return {
            '_': 'InvokeWithMessagesRangeRequest',
            'range': self.range,
            'query': self.query,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_range = reader.tgread_object()
        _args['range'] = _val_range
        _val_query = reader.tgread_object()
        _args['query'] = _val_query
        return cls(**_args)


class InvokeWithReCaptchaRequest(TLRequest):
    """TL type: invokeWithReCaptcha"""
    CONSTRUCTOR_ID = 0xadbb0f94
    SUBCLASS_OF_ID = 0xb7b2364b

    def __init__(self, token: str, query: 'TypeX'):
        self.token = token
        self.query = query

    def to_dict(self):
        return {
            '_': 'InvokeWithReCaptchaRequest',
            'token': self.token,
            'query': self.query,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_token = reader.tgread_string()
        _args['token'] = _val_token
        _val_query = reader.tgread_object()
        _args['query'] = _val_query
        return cls(**_args)


class InvokeWithTakeoutRequest(TLRequest):
    """TL type: invokeWithTakeout"""
    CONSTRUCTOR_ID = 0xaca9fd2e
    SUBCLASS_OF_ID = 0xb7b2364b

    def __init__(self, takeout_id: int, query: 'TypeX'):
        self.takeout_id = takeout_id
        self.query = query

    def to_dict(self):
        return {
            '_': 'InvokeWithTakeoutRequest',
            'takeout_id': self.takeout_id,
            'query': self.query,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_takeout_id = reader.read_long()
        _args['takeout_id'] = _val_takeout_id
        _val_query = reader.tgread_object()
        _args['query'] = _val_query
        return cls(**_args)


class InvokeWithoutUpdatesRequest(TLRequest):
    """TL type: invokeWithoutUpdates"""
    CONSTRUCTOR_ID = 0xbf9459b7
    SUBCLASS_OF_ID = 0xb7b2364b

    def __init__(self, query: 'TypeX'):
        self.query = query

    def to_dict(self):
        return {
            '_': 'InvokeWithoutUpdatesRequest',
            'query': self.query,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_query = reader.tgread_object()
        _args['query'] = _val_query
        return cls(**_args)

