"""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 Albums(TLObject):
    """TL type: stories.albums"""
    CONSTRUCTOR_ID = 0xc3987a3a
    SUBCLASS_OF_ID = 0x05a73d39

    def __init__(self, hash: int, albums: List['TypeStoryAlbum']):
        self.hash = hash
        self.albums = albums

    def to_dict(self):
        return {
            '_': 'Albums',
            'hash': self.hash,
            'albums': self.albums,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_hash = reader.read_long()
        _args['hash'] = _val_hash
        reader.read_int(signed=False)  # skip vector id
        _count_albums = reader.read_int()
        _list_albums = []
        for _ in range(_count_albums):
            _item_albums = reader.tgread_object()
            _list_albums.append(_item_albums)
        _args['albums'] = _list_albums
        return cls(**_args)


class AlbumsNotModified(TLObject):
    """TL type: stories.albumsNotModified"""
    CONSTRUCTOR_ID = 0x564edaeb
    SUBCLASS_OF_ID = 0x05a73d39

    def __init__(self):
        pass

    def to_dict(self):
        return {
            '_': 'AlbumsNotModified',
        }

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

    @classmethod
    def from_reader(cls, reader):
        return cls()


class AllStories(TLObject):
    """TL type: stories.allStories"""
    CONSTRUCTOR_ID = 0x6efc5e81
    SUBCLASS_OF_ID = 0x7e60d0cd

    def __init__(self, count: int, state: str, peer_stories: List['TypePeerStories'], chats: List['TypeChat'], users: List['TypeUser'], stealth_mode: 'TypeStoriesStealthMode', has_more: Optional[bool] = None):
        self.count = count
        self.state = state
        self.peer_stories = peer_stories
        self.chats = chats
        self.users = users
        self.stealth_mode = stealth_mode
        self.has_more = has_more

    def to_dict(self):
        return {
            '_': 'AllStories',
            'count': self.count,
            'state': self.state,
            'peer_stories': self.peer_stories,
            'chats': self.chats,
            'users': self.users,
            'stealth_mode': self.stealth_mode,
            'has_more': self.has_more,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        flags = 0
        if self.has_more:
            flags |= (1 << 0)
        buf.write(struct.pack('<I', flags))
        buf.write(struct.pack('<i', self.count))
        buf.write(TLObject.serialize_bytes(self.state))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.peer_stories)))
        for item in self.peer_stories:
            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))
        buf.write(bytes(self.stealth_mode))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        flags = reader.read_int(signed=False)
        _args['has_more'] = bool(flags & (1 << 0))
        _val_count = reader.read_int()
        _args['count'] = _val_count
        _val_state = reader.tgread_string()
        _args['state'] = _val_state
        reader.read_int(signed=False)  # skip vector id
        _count_peer_stories = reader.read_int()
        _list_peer_stories = []
        for _ in range(_count_peer_stories):
            _item_peer_stories = reader.tgread_object()
            _list_peer_stories.append(_item_peer_stories)
        _args['peer_stories'] = _list_peer_stories
        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_stealth_mode = reader.tgread_object()
        _args['stealth_mode'] = _val_stealth_mode
        return cls(**_args)


class AllStoriesNotModified(TLObject):
    """TL type: stories.allStoriesNotModified"""
    CONSTRUCTOR_ID = 0x1158fe3e
    SUBCLASS_OF_ID = 0x7e60d0cd

    def __init__(self, state: str, stealth_mode: 'TypeStoriesStealthMode'):
        self.state = state
        self.stealth_mode = stealth_mode

    def to_dict(self):
        return {
            '_': 'AllStoriesNotModified',
            'state': self.state,
            'stealth_mode': self.stealth_mode,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        flags = reader.read_int(signed=False)
        _val_state = reader.tgread_string()
        _args['state'] = _val_state
        _val_stealth_mode = reader.tgread_object()
        _args['stealth_mode'] = _val_stealth_mode
        return cls(**_args)


class CanSendStoryCount(TLObject):
    """TL type: stories.canSendStoryCount"""
    CONSTRUCTOR_ID = 0xc387c04e
    SUBCLASS_OF_ID = 0xcb53a298

    def __init__(self, count_remains: int):
        self.count_remains = count_remains

    def to_dict(self):
        return {
            '_': 'CanSendStoryCount',
            'count_remains': self.count_remains,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_count_remains = reader.read_int()
        _args['count_remains'] = _val_count_remains
        return cls(**_args)


class FoundStories(TLObject):
    """TL type: stories.foundStories"""
    CONSTRUCTOR_ID = 0xe2de7737
    SUBCLASS_OF_ID = 0x17790b35

    def __init__(self, count: int, stories: List['TypeFoundStory'], chats: List['TypeChat'], users: List['TypeUser'], next_offset: Optional[str] = None):
        self.count = count
        self.stories = stories
        self.chats = chats
        self.users = users
        self.next_offset = next_offset

    def to_dict(self):
        return {
            '_': 'FoundStories',
            'count': self.count,
            'stories': self.stories,
            'chats': self.chats,
            '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', self.count))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.stories)))
        for item in self.stories:
            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))
        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)
        _val_count = reader.read_int()
        _args['count'] = _val_count
        reader.read_int(signed=False)  # skip vector id
        _count_stories = reader.read_int()
        _list_stories = []
        for _ in range(_count_stories):
            _item_stories = reader.tgread_object()
            _list_stories.append(_item_stories)
        _args['stories'] = _list_stories
        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_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 PeerStories(TLObject):
    """TL type: stories.peerStories"""
    CONSTRUCTOR_ID = 0xcae68768
    SUBCLASS_OF_ID = 0x9d56cfd0

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

    def to_dict(self):
        return {
            '_': 'PeerStories',
            'stories': self.stories,
            '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.stories))
        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_stories = reader.tgread_object()
        _args['stories'] = _val_stories
        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 Stories(TLObject):
    """TL type: stories.stories"""
    CONSTRUCTOR_ID = 0x63c3dd0a
    SUBCLASS_OF_ID = 0x251c0c2c

    def __init__(self, count: int, stories: List['TypeStoryItem'], chats: List['TypeChat'], users: List['TypeUser'], pinned_to_top: Optional[List[int]] = None):
        self.count = count
        self.stories = stories
        self.chats = chats
        self.users = users
        self.pinned_to_top = pinned_to_top

    def to_dict(self):
        return {
            '_': 'Stories',
            'count': self.count,
            'stories': self.stories,
            'chats': self.chats,
            'users': self.users,
            'pinned_to_top': self.pinned_to_top,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        flags = 0
        if self.pinned_to_top is not None:
            flags |= (1 << 0)
        buf.write(struct.pack('<I', flags))
        buf.write(struct.pack('<i', self.count))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.stories)))
        for item in self.stories:
            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))
        if self.pinned_to_top is not None:
            buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
            buf.write(struct.pack('<i', len(self.pinned_to_top)))
            for item in self.pinned_to_top:
                buf.write(struct.pack('<i', self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        flags = reader.read_int(signed=False)
        _val_count = reader.read_int()
        _args['count'] = _val_count
        reader.read_int(signed=False)  # skip vector id
        _count_stories = reader.read_int()
        _list_stories = []
        for _ in range(_count_stories):
            _item_stories = reader.tgread_object()
            _list_stories.append(_item_stories)
        _args['stories'] = _list_stories
        if flags & (1 << 0):
            reader.read_int(signed=False)  # skip vector id
            _count_pinned_to_top = reader.read_int()
            _list_pinned_to_top = []
            for _ in range(_count_pinned_to_top):
                _item_pinned_to_top = reader.read_int()
                _list_pinned_to_top.append(_item_pinned_to_top)
            _args['pinned_to_top'] = _list_pinned_to_top
        else:
            _args['pinned_to_top'] = None
        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 StoryReactionsList(TLObject):
    """TL type: stories.storyReactionsList"""
    CONSTRUCTOR_ID = 0xaa5f789c
    SUBCLASS_OF_ID = 0x046f91e3

    def __init__(self, count: int, reactions: List['TypeStoryReaction'], chats: List['TypeChat'], users: List['TypeUser'], next_offset: Optional[str] = None):
        self.count = count
        self.reactions = reactions
        self.chats = chats
        self.users = users
        self.next_offset = next_offset

    def to_dict(self):
        return {
            '_': 'StoryReactionsList',
            'count': self.count,
            'reactions': self.reactions,
            'chats': self.chats,
            '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', self.count))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.reactions)))
        for item in self.reactions:
            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))
        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)
        _val_count = reader.read_int()
        _args['count'] = _val_count
        reader.read_int(signed=False)  # skip vector id
        _count_reactions = reader.read_int()
        _list_reactions = []
        for _ in range(_count_reactions):
            _item_reactions = reader.tgread_object()
            _list_reactions.append(_item_reactions)
        _args['reactions'] = _list_reactions
        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
        if flags & (1 << 0):
            _val_next_offset = reader.tgread_string()
            _args['next_offset'] = _val_next_offset
        else:
            _args['next_offset'] = None
        return cls(**_args)


class StoryViews(TLObject):
    """TL type: stories.storyViews"""
    CONSTRUCTOR_ID = 0xde9eed1d
    SUBCLASS_OF_ID = 0x4b3fc4ba

    def __init__(self, views: List['TypeStoryViews'], users: List['TypeUser']):
        self.views = views
        self.users = users

    def to_dict(self):
        return {
            '_': 'StoryViews',
            'views': self.views,
            '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.views)))
        for item in self.views:
            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_views = reader.read_int()
        _list_views = []
        for _ in range(_count_views):
            _item_views = reader.tgread_object()
            _list_views.append(_item_views)
        _args['views'] = _list_views
        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 StoryViewsList(TLObject):
    """TL type: stories.storyViewsList"""
    CONSTRUCTOR_ID = 0x59d78fc5
    SUBCLASS_OF_ID = 0xb9437560

    def __init__(self, count: int, views_count: int, forwards_count: int, reactions_count: int, views: List['TypeStoryView'], chats: List['TypeChat'], users: List['TypeUser'], next_offset: Optional[str] = None):
        self.count = count
        self.views_count = views_count
        self.forwards_count = forwards_count
        self.reactions_count = reactions_count
        self.views = views
        self.chats = chats
        self.users = users
        self.next_offset = next_offset

    def to_dict(self):
        return {
            '_': 'StoryViewsList',
            'count': self.count,
            'views_count': self.views_count,
            'forwards_count': self.forwards_count,
            'reactions_count': self.reactions_count,
            'views': self.views,
            'chats': self.chats,
            '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', self.count))
        buf.write(struct.pack('<i', self.views_count))
        buf.write(struct.pack('<i', self.forwards_count))
        buf.write(struct.pack('<i', self.reactions_count))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.views)))
        for item in self.views:
            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))
        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)
        _val_count = reader.read_int()
        _args['count'] = _val_count
        _val_views_count = reader.read_int()
        _args['views_count'] = _val_views_count
        _val_forwards_count = reader.read_int()
        _args['forwards_count'] = _val_forwards_count
        _val_reactions_count = reader.read_int()
        _args['reactions_count'] = _val_reactions_count
        reader.read_int(signed=False)  # skip vector id
        _count_views = reader.read_int()
        _list_views = []
        for _ in range(_count_views):
            _item_views = reader.tgread_object()
            _list_views.append(_item_views)
        _args['views'] = _list_views
        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
        if flags & (1 << 0):
            _val_next_offset = reader.tgread_string()
            _args['next_offset'] = _val_next_offset
        else:
            _args['next_offset'] = None
        return cls(**_args)

