"""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 ExportedGroupCallInvite(TLObject):
    """TL type: phone.exportedGroupCallInvite"""
    CONSTRUCTOR_ID = 0x204bd158
    SUBCLASS_OF_ID = 0x3b3bfe8f

    def __init__(self, link: str):
        self.link = link

    def to_dict(self):
        return {
            '_': 'ExportedGroupCallInvite',
            'link': self.link,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_link = reader.tgread_string()
        _args['link'] = _val_link
        return cls(**_args)


class GroupCall(TLObject):
    """TL type: phone.groupCall"""
    CONSTRUCTOR_ID = 0x9e727aad
    SUBCLASS_OF_ID = 0x304116be

    def __init__(self, call: 'TypeGroupCall', participants: List['TypeGroupCallParticipant'], participants_next_offset: str, chats: List['TypeChat'], users: List['TypeUser']):
        self.call = call
        self.participants = participants
        self.participants_next_offset = participants_next_offset
        self.chats = chats
        self.users = users

    def to_dict(self):
        return {
            '_': 'GroupCall',
            'call': self.call,
            'participants': self.participants,
            'participants_next_offset': self.participants_next_offset,
            'chats': self.chats,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(bytes(self.call))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.participants)))
        for item in self.participants:
            buf.write(bytes(self.item))
        buf.write(TLObject.serialize_bytes(self.participants_next_offset))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.chats)))
        for item in self.chats:
            buf.write(bytes(self.item))
        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))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_call = reader.tgread_object()
        _args['call'] = _val_call
        reader.read_int(signed=False)  # skip vector id
        _count_participants = reader.read_int()
        _list_participants = []
        for _ in range(_count_participants):
            _item_participants = reader.tgread_object()
            _list_participants.append(_item_participants)
        _args['participants'] = _list_participants
        _val_participants_next_offset = reader.tgread_string()
        _args['participants_next_offset'] = _val_participants_next_offset
        reader.read_int(signed=False)  # skip vector id
        _count_chats = reader.read_int()
        _list_chats = []
        for _ in range(_count_chats):
            _item_chats = reader.tgread_object()
            _list_chats.append(_item_chats)
        _args['chats'] = _list_chats
        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 GroupCallStars(TLObject):
    """TL type: phone.groupCallStars"""
    CONSTRUCTOR_ID = 0x9d1dbd26
    SUBCLASS_OF_ID = 0xb447801a

    def __init__(self, total_stars: int, top_donors: List['TypeGroupCallDonor'], chats: List['TypeChat'], users: List['TypeUser']):
        self.total_stars = total_stars
        self.top_donors = top_donors
        self.chats = chats
        self.users = users

    def to_dict(self):
        return {
            '_': 'GroupCallStars',
            'total_stars': self.total_stars,
            'top_donors': self.top_donors,
            'chats': self.chats,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<q', self.total_stars))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.top_donors)))
        for item in self.top_donors:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.chats)))
        for item in self.chats:
            buf.write(bytes(self.item))
        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))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_total_stars = reader.read_long()
        _args['total_stars'] = _val_total_stars
        reader.read_int(signed=False)  # skip vector id
        _count_top_donors = reader.read_int()
        _list_top_donors = []
        for _ in range(_count_top_donors):
            _item_top_donors = reader.tgread_object()
            _list_top_donors.append(_item_top_donors)
        _args['top_donors'] = _list_top_donors
        reader.read_int(signed=False)  # skip vector id
        _count_chats = reader.read_int()
        _list_chats = []
        for _ in range(_count_chats):
            _item_chats = reader.tgread_object()
            _list_chats.append(_item_chats)
        _args['chats'] = _list_chats
        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 GroupCallStreamChannels(TLObject):
    """TL type: phone.groupCallStreamChannels"""
    CONSTRUCTOR_ID = 0xd0e482b2
    SUBCLASS_OF_ID = 0x9157c5e4

    def __init__(self, channels: List['TypeGroupCallStreamChannel']):
        self.channels = channels

    def to_dict(self):
        return {
            '_': 'GroupCallStreamChannels',
            'channels': self.channels,
        }

    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.channels)))
        for item in self.channels:
            buf.write(bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        reader.read_int(signed=False)  # skip vector id
        _count_channels = reader.read_int()
        _list_channels = []
        for _ in range(_count_channels):
            _item_channels = reader.tgread_object()
            _list_channels.append(_item_channels)
        _args['channels'] = _list_channels
        return cls(**_args)


class GroupCallStreamRtmpUrl(TLObject):
    """TL type: phone.groupCallStreamRtmpUrl"""
    CONSTRUCTOR_ID = 0x2dbf3432
    SUBCLASS_OF_ID = 0xd1f515cb

    def __init__(self, url: str, key: str):
        self.url = url
        self.key = key

    def to_dict(self):
        return {
            '_': 'GroupCallStreamRtmpUrl',
            'url': self.url,
            'key': self.key,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_url = reader.tgread_string()
        _args['url'] = _val_url
        _val_key = reader.tgread_string()
        _args['key'] = _val_key
        return cls(**_args)


class GroupParticipants(TLObject):
    """TL type: phone.groupParticipants"""
    CONSTRUCTOR_ID = 0xf47751b6
    SUBCLASS_OF_ID = 0x72d304f4

    def __init__(self, count: int, participants: List['TypeGroupCallParticipant'], next_offset: str, chats: List['TypeChat'], users: List['TypeUser'], version: int):
        self.count = count
        self.participants = participants
        self.next_offset = next_offset
        self.chats = chats
        self.users = users
        self.version = version

    def to_dict(self):
        return {
            '_': 'GroupParticipants',
            'count': self.count,
            'participants': self.participants,
            'next_offset': self.next_offset,
            'chats': self.chats,
            'users': self.users,
            'version': self.version,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<i', self.count))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.participants)))
        for item in self.participants:
            buf.write(bytes(self.item))
        buf.write(TLObject.serialize_bytes(self.next_offset))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.chats)))
        for item in self.chats:
            buf.write(bytes(self.item))
        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))
        buf.write(struct.pack('<i', self.version))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_count = reader.read_int()
        _args['count'] = _val_count
        reader.read_int(signed=False)  # skip vector id
        _count_participants = reader.read_int()
        _list_participants = []
        for _ in range(_count_participants):
            _item_participants = reader.tgread_object()
            _list_participants.append(_item_participants)
        _args['participants'] = _list_participants
        _val_next_offset = reader.tgread_string()
        _args['next_offset'] = _val_next_offset
        reader.read_int(signed=False)  # skip vector id
        _count_chats = reader.read_int()
        _list_chats = []
        for _ in range(_count_chats):
            _item_chats = reader.tgread_object()
            _list_chats.append(_item_chats)
        _args['chats'] = _list_chats
        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
        _val_version = reader.read_int()
        _args['version'] = _val_version
        return cls(**_args)


class JoinAsPeers(TLObject):
    """TL type: phone.joinAsPeers"""
    CONSTRUCTOR_ID = 0xafe5623f
    SUBCLASS_OF_ID = 0xb4b770fb

    def __init__(self, peers: List['TypePeer'], chats: List['TypeChat'], users: List['TypeUser']):
        self.peers = peers
        self.chats = chats
        self.users = users

    def to_dict(self):
        return {
            '_': 'JoinAsPeers',
            'peers': self.peers,
            'chats': self.chats,
            'users': self.users,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        reader.read_int(signed=False)  # skip vector id
        _count_peers = reader.read_int()
        _list_peers = []
        for _ in range(_count_peers):
            _item_peers = reader.tgread_object()
            _list_peers.append(_item_peers)
        _args['peers'] = _list_peers
        reader.read_int(signed=False)  # skip vector id
        _count_chats = reader.read_int()
        _list_chats = []
        for _ in range(_count_chats):
            _item_chats = reader.tgread_object()
            _list_chats.append(_item_chats)
        _args['chats'] = _list_chats
        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 PhoneCall(TLObject):
    """TL type: phone.phoneCall"""
    CONSTRUCTOR_ID = 0xec82e140
    SUBCLASS_OF_ID = 0xd48afe4f

    def __init__(self, phone_call: 'TypePhoneCall', users: List['TypeUser']):
        self.phone_call = phone_call
        self.users = users

    def to_dict(self):
        return {
            '_': 'PhoneCall',
            'phone_call': self.phone_call,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(bytes(self.phone_call))
        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))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_phone_call = reader.tgread_object()
        _args['phone_call'] = _val_phone_call
        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)

