"""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 BotInfo(TLObject):
    """TL type: bots.botInfo"""
    CONSTRUCTOR_ID = 0xe8a775b0
    SUBCLASS_OF_ID = 0xca7b2235

    def __init__(self, name: str, about: str, description: str):
        self.name = name
        self.about = about
        self.description = description

    def to_dict(self):
        return {
            '_': 'BotInfo',
            'name': self.name,
            'about': self.about,
            'description': self.description,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_name = reader.tgread_string()
        _args['name'] = _val_name
        _val_about = reader.tgread_string()
        _args['about'] = _val_about
        _val_description = reader.tgread_string()
        _args['description'] = _val_description
        return cls(**_args)


class PopularAppBots(TLObject):
    """TL type: bots.popularAppBots"""
    CONSTRUCTOR_ID = 0x1991b13b
    SUBCLASS_OF_ID = 0x7b64be7d

    def __init__(self, users: List['TypeUser'], next_offset: Optional[str] = None):
        self.users = users
        self.next_offset = next_offset

    def to_dict(self):
        return {
            '_': 'PopularAppBots',
            'users': self.users,
            'next_offset': self.next_offset,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        flags = 0
        if self.next_offset is not None:
            flags |= (1 << 0)
        buf.write(struct.pack('<I', flags))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.users)))
        for item in self.users:
            buf.write(bytes(self.item))
        if self.next_offset is not None:
            buf.write(TLObject.serialize_bytes(self.next_offset))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        flags = reader.read_int(signed=False)
        if flags & (1 << 0):
            _val_next_offset = reader.tgread_string()
            _args['next_offset'] = _val_next_offset
        else:
            _args['next_offset'] = None
        reader.read_int(signed=False)  # skip vector id
        _count_users = reader.read_int()
        _list_users = []
        for _ in range(_count_users):
            _item_users = reader.tgread_object()
            _list_users.append(_item_users)
        _args['users'] = _list_users
        return cls(**_args)


class PreviewInfo(TLObject):
    """TL type: bots.previewInfo"""
    CONSTRUCTOR_ID = 0x0ca71d64
    SUBCLASS_OF_ID = 0xf0c27f35

    def __init__(self, media: List['TypeBotPreviewMedia'], lang_codes: List[str]):
        self.media = media
        self.lang_codes = lang_codes

    def to_dict(self):
        return {
            '_': 'PreviewInfo',
            'media': self.media,
            'lang_codes': self.lang_codes,
        }

    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.media)))
        for item in self.media:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.lang_codes)))
        for item in self.lang_codes:
            buf.write(TLObject.serialize_bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        reader.read_int(signed=False)  # skip vector id
        _count_media = reader.read_int()
        _list_media = []
        for _ in range(_count_media):
            _item_media = reader.tgread_object()
            _list_media.append(_item_media)
        _args['media'] = _list_media
        reader.read_int(signed=False)  # skip vector id
        _count_lang_codes = reader.read_int()
        _list_lang_codes = []
        for _ in range(_count_lang_codes):
            _item_lang_codes = reader.tgread_string()
            _list_lang_codes.append(_item_lang_codes)
        _args['lang_codes'] = _list_lang_codes
        return cls(**_args)

