"""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 GetBroadcastStatsRequest(TLRequest):
    """TL type: stats.getBroadcastStats"""
    CONSTRUCTOR_ID = 0xab42441a
    SUBCLASS_OF_ID = 0x7ff25428

    def __init__(self, channel: 'TypeInputChannel', dark: Optional[bool] = None):
        self.channel = channel
        self.dark = dark

    def to_dict(self):
        return {
            '_': 'GetBroadcastStatsRequest',
            'channel': self.channel,
            'dark': self.dark,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        flags = 0
        if self.dark:
            flags |= (1 << 0)
        buf.write(struct.pack('<I', flags))
        buf.write(bytes(self.channel))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        flags = reader.read_int(signed=False)
        _args['dark'] = bool(flags & (1 << 0))
        _val_channel = reader.tgread_object()
        _args['channel'] = _val_channel
        return cls(**_args)


class GetMegagroupStatsRequest(TLRequest):
    """TL type: stats.getMegagroupStats"""
    CONSTRUCTOR_ID = 0xdcdf8607
    SUBCLASS_OF_ID = 0x5b59be8d

    def __init__(self, channel: 'TypeInputChannel', dark: Optional[bool] = None):
        self.channel = channel
        self.dark = dark

    def to_dict(self):
        return {
            '_': 'GetMegagroupStatsRequest',
            'channel': self.channel,
            'dark': self.dark,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        flags = 0
        if self.dark:
            flags |= (1 << 0)
        buf.write(struct.pack('<I', flags))
        buf.write(bytes(self.channel))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        flags = reader.read_int(signed=False)
        _args['dark'] = bool(flags & (1 << 0))
        _val_channel = reader.tgread_object()
        _args['channel'] = _val_channel
        return cls(**_args)


class GetMessagePublicForwardsRequest(TLRequest):
    """TL type: stats.getMessagePublicForwards"""
    CONSTRUCTOR_ID = 0x5f150144
    SUBCLASS_OF_ID = 0xa7283211

    def __init__(self, channel: 'TypeInputChannel', msg_id: int, offset: str, limit: int):
        self.channel = channel
        self.msg_id = msg_id
        self.offset = offset
        self.limit = limit

    def to_dict(self):
        return {
            '_': 'GetMessagePublicForwardsRequest',
            'channel': self.channel,
            'msg_id': self.msg_id,
            'offset': self.offset,
            'limit': self.limit,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_channel = reader.tgread_object()
        _args['channel'] = _val_channel
        _val_msg_id = reader.read_int()
        _args['msg_id'] = _val_msg_id
        _val_offset = reader.tgread_string()
        _args['offset'] = _val_offset
        _val_limit = reader.read_int()
        _args['limit'] = _val_limit
        return cls(**_args)


class GetMessageStatsRequest(TLRequest):
    """TL type: stats.getMessageStats"""
    CONSTRUCTOR_ID = 0xb6e0a3f5
    SUBCLASS_OF_ID = 0x9604a322

    def __init__(self, channel: 'TypeInputChannel', msg_id: int, dark: Optional[bool] = None):
        self.channel = channel
        self.msg_id = msg_id
        self.dark = dark

    def to_dict(self):
        return {
            '_': 'GetMessageStatsRequest',
            'channel': self.channel,
            'msg_id': self.msg_id,
            'dark': self.dark,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        flags = 0
        if self.dark:
            flags |= (1 << 0)
        buf.write(struct.pack('<I', flags))
        buf.write(bytes(self.channel))
        buf.write(struct.pack('<i', self.msg_id))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        flags = reader.read_int(signed=False)
        _args['dark'] = bool(flags & (1 << 0))
        _val_channel = reader.tgread_object()
        _args['channel'] = _val_channel
        _val_msg_id = reader.read_int()
        _args['msg_id'] = _val_msg_id
        return cls(**_args)


class GetStoryPublicForwardsRequest(TLRequest):
    """TL type: stats.getStoryPublicForwards"""
    CONSTRUCTOR_ID = 0xa6437ef6
    SUBCLASS_OF_ID = 0xa7283211

    def __init__(self, peer: 'TypeInputPeer', id: int, offset: str, limit: int):
        self.peer = peer
        self.id = id
        self.offset = offset
        self.limit = limit

    def to_dict(self):
        return {
            '_': 'GetStoryPublicForwardsRequest',
            'peer': self.peer,
            'id': self.id,
            'offset': self.offset,
            'limit': self.limit,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_peer = reader.tgread_object()
        _args['peer'] = _val_peer
        _val_id = reader.read_int()
        _args['id'] = _val_id
        _val_offset = reader.tgread_string()
        _args['offset'] = _val_offset
        _val_limit = reader.read_int()
        _args['limit'] = _val_limit
        return cls(**_args)


class GetStoryStatsRequest(TLRequest):
    """TL type: stats.getStoryStats"""
    CONSTRUCTOR_ID = 0x374fef40
    SUBCLASS_OF_ID = 0x8b4d43d4

    def __init__(self, peer: 'TypeInputPeer', id: int, dark: Optional[bool] = None):
        self.peer = peer
        self.id = id
        self.dark = dark

    def to_dict(self):
        return {
            '_': 'GetStoryStatsRequest',
            'peer': self.peer,
            'id': self.id,
            'dark': self.dark,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        flags = 0
        if self.dark:
            flags |= (1 << 0)
        buf.write(struct.pack('<I', flags))
        buf.write(bytes(self.peer))
        buf.write(struct.pack('<i', self.id))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        flags = reader.read_int(signed=False)
        _args['dark'] = bool(flags & (1 << 0))
        _val_peer = reader.tgread_object()
        _args['peer'] = _val_peer
        _val_id = reader.read_int()
        _args['id'] = _val_id
        return cls(**_args)


class LoadAsyncGraphRequest(TLRequest):
    """TL type: stats.loadAsyncGraph"""
    CONSTRUCTOR_ID = 0x621d5fa0
    SUBCLASS_OF_ID = 0x9b903153

    def __init__(self, token: str, x: Optional[int] = None):
        self.token = token
        self.x = x

    def to_dict(self):
        return {
            '_': 'LoadAsyncGraphRequest',
            'token': self.token,
            'x': self.x,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        flags = 0
        if self.x is not None:
            flags |= (1 << 0)
        buf.write(struct.pack('<I', flags))
        buf.write(TLObject.serialize_bytes(self.token))
        if self.x is not None:
            buf.write(struct.pack('<q', self.x))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        flags = reader.read_int(signed=False)
        _val_token = reader.tgread_string()
        _args['token'] = _val_token
        if flags & (1 << 0):
            _val_x = reader.read_long()
            _args['x'] = _val_x
        else:
            _args['x'] = None
        return cls(**_args)

