"""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 BroadcastStats(TLObject):
    """TL type: stats.broadcastStats"""
    CONSTRUCTOR_ID = 0x396ca5fc
    SUBCLASS_OF_ID = 0x7ff25428

    def __init__(self, period: 'TypeStatsDateRangeDays', followers: 'TypeStatsAbsValueAndPrev', views_per_post: 'TypeStatsAbsValueAndPrev', shares_per_post: 'TypeStatsAbsValueAndPrev', reactions_per_post: 'TypeStatsAbsValueAndPrev', views_per_story: 'TypeStatsAbsValueAndPrev', shares_per_story: 'TypeStatsAbsValueAndPrev', reactions_per_story: 'TypeStatsAbsValueAndPrev', enabled_notifications: 'TypeStatsPercentValue', growth_graph: 'TypeStatsGraph', followers_graph: 'TypeStatsGraph', mute_graph: 'TypeStatsGraph', top_hours_graph: 'TypeStatsGraph', interactions_graph: 'TypeStatsGraph', iv_interactions_graph: 'TypeStatsGraph', views_by_source_graph: 'TypeStatsGraph', new_followers_by_source_graph: 'TypeStatsGraph', languages_graph: 'TypeStatsGraph', reactions_by_emotion_graph: 'TypeStatsGraph', story_interactions_graph: 'TypeStatsGraph', story_reactions_by_emotion_graph: 'TypeStatsGraph', recent_posts_interactions: List['TypePostInteractionCounters']):
        self.period = period
        self.followers = followers
        self.views_per_post = views_per_post
        self.shares_per_post = shares_per_post
        self.reactions_per_post = reactions_per_post
        self.views_per_story = views_per_story
        self.shares_per_story = shares_per_story
        self.reactions_per_story = reactions_per_story
        self.enabled_notifications = enabled_notifications
        self.growth_graph = growth_graph
        self.followers_graph = followers_graph
        self.mute_graph = mute_graph
        self.top_hours_graph = top_hours_graph
        self.interactions_graph = interactions_graph
        self.iv_interactions_graph = iv_interactions_graph
        self.views_by_source_graph = views_by_source_graph
        self.new_followers_by_source_graph = new_followers_by_source_graph
        self.languages_graph = languages_graph
        self.reactions_by_emotion_graph = reactions_by_emotion_graph
        self.story_interactions_graph = story_interactions_graph
        self.story_reactions_by_emotion_graph = story_reactions_by_emotion_graph
        self.recent_posts_interactions = recent_posts_interactions

    def to_dict(self):
        return {
            '_': 'BroadcastStats',
            'period': self.period,
            'followers': self.followers,
            'views_per_post': self.views_per_post,
            'shares_per_post': self.shares_per_post,
            'reactions_per_post': self.reactions_per_post,
            'views_per_story': self.views_per_story,
            'shares_per_story': self.shares_per_story,
            'reactions_per_story': self.reactions_per_story,
            'enabled_notifications': self.enabled_notifications,
            'growth_graph': self.growth_graph,
            'followers_graph': self.followers_graph,
            'mute_graph': self.mute_graph,
            'top_hours_graph': self.top_hours_graph,
            'interactions_graph': self.interactions_graph,
            'iv_interactions_graph': self.iv_interactions_graph,
            'views_by_source_graph': self.views_by_source_graph,
            'new_followers_by_source_graph': self.new_followers_by_source_graph,
            'languages_graph': self.languages_graph,
            'reactions_by_emotion_graph': self.reactions_by_emotion_graph,
            'story_interactions_graph': self.story_interactions_graph,
            'story_reactions_by_emotion_graph': self.story_reactions_by_emotion_graph,
            'recent_posts_interactions': self.recent_posts_interactions,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(bytes(self.period))
        buf.write(bytes(self.followers))
        buf.write(bytes(self.views_per_post))
        buf.write(bytes(self.shares_per_post))
        buf.write(bytes(self.reactions_per_post))
        buf.write(bytes(self.views_per_story))
        buf.write(bytes(self.shares_per_story))
        buf.write(bytes(self.reactions_per_story))
        buf.write(bytes(self.enabled_notifications))
        buf.write(bytes(self.growth_graph))
        buf.write(bytes(self.followers_graph))
        buf.write(bytes(self.mute_graph))
        buf.write(bytes(self.top_hours_graph))
        buf.write(bytes(self.interactions_graph))
        buf.write(bytes(self.iv_interactions_graph))
        buf.write(bytes(self.views_by_source_graph))
        buf.write(bytes(self.new_followers_by_source_graph))
        buf.write(bytes(self.languages_graph))
        buf.write(bytes(self.reactions_by_emotion_graph))
        buf.write(bytes(self.story_interactions_graph))
        buf.write(bytes(self.story_reactions_by_emotion_graph))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.recent_posts_interactions)))
        for item in self.recent_posts_interactions:
            buf.write(bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_period = reader.tgread_object()
        _args['period'] = _val_period
        _val_followers = reader.tgread_object()
        _args['followers'] = _val_followers
        _val_views_per_post = reader.tgread_object()
        _args['views_per_post'] = _val_views_per_post
        _val_shares_per_post = reader.tgread_object()
        _args['shares_per_post'] = _val_shares_per_post
        _val_reactions_per_post = reader.tgread_object()
        _args['reactions_per_post'] = _val_reactions_per_post
        _val_views_per_story = reader.tgread_object()
        _args['views_per_story'] = _val_views_per_story
        _val_shares_per_story = reader.tgread_object()
        _args['shares_per_story'] = _val_shares_per_story
        _val_reactions_per_story = reader.tgread_object()
        _args['reactions_per_story'] = _val_reactions_per_story
        _val_enabled_notifications = reader.tgread_object()
        _args['enabled_notifications'] = _val_enabled_notifications
        _val_growth_graph = reader.tgread_object()
        _args['growth_graph'] = _val_growth_graph
        _val_followers_graph = reader.tgread_object()
        _args['followers_graph'] = _val_followers_graph
        _val_mute_graph = reader.tgread_object()
        _args['mute_graph'] = _val_mute_graph
        _val_top_hours_graph = reader.tgread_object()
        _args['top_hours_graph'] = _val_top_hours_graph
        _val_interactions_graph = reader.tgread_object()
        _args['interactions_graph'] = _val_interactions_graph
        _val_iv_interactions_graph = reader.tgread_object()
        _args['iv_interactions_graph'] = _val_iv_interactions_graph
        _val_views_by_source_graph = reader.tgread_object()
        _args['views_by_source_graph'] = _val_views_by_source_graph
        _val_new_followers_by_source_graph = reader.tgread_object()
        _args['new_followers_by_source_graph'] = _val_new_followers_by_source_graph
        _val_languages_graph = reader.tgread_object()
        _args['languages_graph'] = _val_languages_graph
        _val_reactions_by_emotion_graph = reader.tgread_object()
        _args['reactions_by_emotion_graph'] = _val_reactions_by_emotion_graph
        _val_story_interactions_graph = reader.tgread_object()
        _args['story_interactions_graph'] = _val_story_interactions_graph
        _val_story_reactions_by_emotion_graph = reader.tgread_object()
        _args['story_reactions_by_emotion_graph'] = _val_story_reactions_by_emotion_graph
        reader.read_int(signed=False)  # skip vector id
        _count_recent_posts_interactions = reader.read_int()
        _list_recent_posts_interactions = []
        for _ in range(_count_recent_posts_interactions):
            _item_recent_posts_interactions = reader.tgread_object()
            _list_recent_posts_interactions.append(_item_recent_posts_interactions)
        _args['recent_posts_interactions'] = _list_recent_posts_interactions
        return cls(**_args)


class MegagroupStats(TLObject):
    """TL type: stats.megagroupStats"""
    CONSTRUCTOR_ID = 0xef7ff916
    SUBCLASS_OF_ID = 0x5b59be8d

    def __init__(self, period: 'TypeStatsDateRangeDays', members: 'TypeStatsAbsValueAndPrev', messages: 'TypeStatsAbsValueAndPrev', viewers: 'TypeStatsAbsValueAndPrev', posters: 'TypeStatsAbsValueAndPrev', growth_graph: 'TypeStatsGraph', members_graph: 'TypeStatsGraph', new_members_by_source_graph: 'TypeStatsGraph', languages_graph: 'TypeStatsGraph', messages_graph: 'TypeStatsGraph', actions_graph: 'TypeStatsGraph', top_hours_graph: 'TypeStatsGraph', weekdays_graph: 'TypeStatsGraph', top_posters: List['TypeStatsGroupTopPoster'], top_admins: List['TypeStatsGroupTopAdmin'], top_inviters: List['TypeStatsGroupTopInviter'], users: List['TypeUser']):
        self.period = period
        self.members = members
        self.messages = messages
        self.viewers = viewers
        self.posters = posters
        self.growth_graph = growth_graph
        self.members_graph = members_graph
        self.new_members_by_source_graph = new_members_by_source_graph
        self.languages_graph = languages_graph
        self.messages_graph = messages_graph
        self.actions_graph = actions_graph
        self.top_hours_graph = top_hours_graph
        self.weekdays_graph = weekdays_graph
        self.top_posters = top_posters
        self.top_admins = top_admins
        self.top_inviters = top_inviters
        self.users = users

    def to_dict(self):
        return {
            '_': 'MegagroupStats',
            'period': self.period,
            'members': self.members,
            'messages': self.messages,
            'viewers': self.viewers,
            'posters': self.posters,
            'growth_graph': self.growth_graph,
            'members_graph': self.members_graph,
            'new_members_by_source_graph': self.new_members_by_source_graph,
            'languages_graph': self.languages_graph,
            'messages_graph': self.messages_graph,
            'actions_graph': self.actions_graph,
            'top_hours_graph': self.top_hours_graph,
            'weekdays_graph': self.weekdays_graph,
            'top_posters': self.top_posters,
            'top_admins': self.top_admins,
            'top_inviters': self.top_inviters,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(bytes(self.period))
        buf.write(bytes(self.members))
        buf.write(bytes(self.messages))
        buf.write(bytes(self.viewers))
        buf.write(bytes(self.posters))
        buf.write(bytes(self.growth_graph))
        buf.write(bytes(self.members_graph))
        buf.write(bytes(self.new_members_by_source_graph))
        buf.write(bytes(self.languages_graph))
        buf.write(bytes(self.messages_graph))
        buf.write(bytes(self.actions_graph))
        buf.write(bytes(self.top_hours_graph))
        buf.write(bytes(self.weekdays_graph))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.top_posters)))
        for item in self.top_posters:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.top_admins)))
        for item in self.top_admins:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.top_inviters)))
        for item in self.top_inviters:
            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_period = reader.tgread_object()
        _args['period'] = _val_period
        _val_members = reader.tgread_object()
        _args['members'] = _val_members
        _val_messages = reader.tgread_object()
        _args['messages'] = _val_messages
        _val_viewers = reader.tgread_object()
        _args['viewers'] = _val_viewers
        _val_posters = reader.tgread_object()
        _args['posters'] = _val_posters
        _val_growth_graph = reader.tgread_object()
        _args['growth_graph'] = _val_growth_graph
        _val_members_graph = reader.tgread_object()
        _args['members_graph'] = _val_members_graph
        _val_new_members_by_source_graph = reader.tgread_object()
        _args['new_members_by_source_graph'] = _val_new_members_by_source_graph
        _val_languages_graph = reader.tgread_object()
        _args['languages_graph'] = _val_languages_graph
        _val_messages_graph = reader.tgread_object()
        _args['messages_graph'] = _val_messages_graph
        _val_actions_graph = reader.tgread_object()
        _args['actions_graph'] = _val_actions_graph
        _val_top_hours_graph = reader.tgread_object()
        _args['top_hours_graph'] = _val_top_hours_graph
        _val_weekdays_graph = reader.tgread_object()
        _args['weekdays_graph'] = _val_weekdays_graph
        reader.read_int(signed=False)  # skip vector id
        _count_top_posters = reader.read_int()
        _list_top_posters = []
        for _ in range(_count_top_posters):
            _item_top_posters = reader.tgread_object()
            _list_top_posters.append(_item_top_posters)
        _args['top_posters'] = _list_top_posters
        reader.read_int(signed=False)  # skip vector id
        _count_top_admins = reader.read_int()
        _list_top_admins = []
        for _ in range(_count_top_admins):
            _item_top_admins = reader.tgread_object()
            _list_top_admins.append(_item_top_admins)
        _args['top_admins'] = _list_top_admins
        reader.read_int(signed=False)  # skip vector id
        _count_top_inviters = reader.read_int()
        _list_top_inviters = []
        for _ in range(_count_top_inviters):
            _item_top_inviters = reader.tgread_object()
            _list_top_inviters.append(_item_top_inviters)
        _args['top_inviters'] = _list_top_inviters
        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 MessageStats(TLObject):
    """TL type: stats.messageStats"""
    CONSTRUCTOR_ID = 0x7fe91c14
    SUBCLASS_OF_ID = 0x9604a322

    def __init__(self, views_graph: 'TypeStatsGraph', reactions_by_emotion_graph: 'TypeStatsGraph'):
        self.views_graph = views_graph
        self.reactions_by_emotion_graph = reactions_by_emotion_graph

    def to_dict(self):
        return {
            '_': 'MessageStats',
            'views_graph': self.views_graph,
            'reactions_by_emotion_graph': self.reactions_by_emotion_graph,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_views_graph = reader.tgread_object()
        _args['views_graph'] = _val_views_graph
        _val_reactions_by_emotion_graph = reader.tgread_object()
        _args['reactions_by_emotion_graph'] = _val_reactions_by_emotion_graph
        return cls(**_args)


class PublicForwards(TLObject):
    """TL type: stats.publicForwards"""
    CONSTRUCTOR_ID = 0x93037e20
    SUBCLASS_OF_ID = 0xa7283211

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

    def to_dict(self):
        return {
            '_': 'PublicForwards',
            'count': self.count,
            'forwards': self.forwards,
            '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.forwards)))
        for item in self.forwards:
            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_forwards = reader.read_int()
        _list_forwards = []
        for _ in range(_count_forwards):
            _item_forwards = reader.tgread_object()
            _list_forwards.append(_item_forwards)
        _args['forwards'] = _list_forwards
        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 StoryStats(TLObject):
    """TL type: stats.storyStats"""
    CONSTRUCTOR_ID = 0x50cd067c
    SUBCLASS_OF_ID = 0x8b4d43d4

    def __init__(self, views_graph: 'TypeStatsGraph', reactions_by_emotion_graph: 'TypeStatsGraph'):
        self.views_graph = views_graph
        self.reactions_by_emotion_graph = reactions_by_emotion_graph

    def to_dict(self):
        return {
            '_': 'StoryStats',
            'views_graph': self.views_graph,
            'reactions_by_emotion_graph': self.reactions_by_emotion_graph,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_views_graph = reader.tgread_object()
        _args['views_graph'] = _val_views_graph
        _val_reactions_by_emotion_graph = reader.tgread_object()
        _args['reactions_by_emotion_graph'] = _val_reactions_by_emotion_graph
        return cls(**_args)

