# Path: telethon/types/_core/tlmessage.py
# class TLMessage(tlobject.TLObject):
#     """
#     https://core.telegram.org/mtproto/service_messages#simple-container.
# 
#     Messages are what's ultimately sent to Telegram:
#         message msg_id:long seqno:int bytes:int body:bytes = Message;
# 
#     Each message has its own unique identifier, and the body is simply
#     the serialized request that should be executed on the server, or
#     the response object from Telegram. Since the body is always a valid
#     object, it makes sense to store the object and not the bytes to
#     ease working with them.
# 
#     There is no need to add serializing logic here since that can be
#     inlined and is unlikely to change. Thus these are only needed to
#     encapsulate responses.
#     """
#     SIZE_OVERHEAD = 12
# 
#     def __init__(self, msg_id, seq_no, obj):
#         self.msg_id = msg_id
#         self.seq_no = seq_no
#         self.obj = obj
# 
#     def to_dict(self):
#         return {
#             '_': 'TLMessage',
#             'msg_id': self.msg_id,
#             'seq_no': self.seq_no,
#             'obj': self.obj
#         }
# 
# Path: telethon/_misc/tlobject.py
# class TLObject:
#     __slots__ = ()
#     CONSTRUCTOR_ID = None
#     SUBCLASS_OF_ID = None
# 
#     @staticmethod
#     def _serialize_bytes(data):
#         """Write bytes by using Telegram guidelines"""
#         if not isinstance(data, bytes):
#             if isinstance(data, str):
#                 data = data.encode('utf-8')
#             else:
#                 raise TypeError(
#                     'bytes or str expected, not {}'.format(type(data)))
# 
#         r = []
#         if len(data) < 254:
#             padding = (len(data) + 1) % 4
#             if padding != 0:
#                 padding = 4 - padding
# 
#             r.append(bytes([len(data)]))
#             r.append(data)
# 
#         else:
#             padding = len(data) % 4
#             if padding != 0:
#                 padding = 4 - padding
# 
#             r.append(bytes([
#                 254,
#                 len(data) % 256,
#                 (len(data) >> 8) % 256,
#                 (len(data) >> 16) % 256
#             ]))
#             r.append(data)
# 
#         r.append(bytes(padding))
#         return b''.join(r)
# 
#     @staticmethod
#     def _serialize_datetime(dt):
#         if not dt and not isinstance(dt, timedelta):
#             return b'\0\0\0\0'
# 
#         if isinstance(dt, datetime):
#             dt = _datetime_to_timestamp(dt)
#         elif isinstance(dt, date):
#             dt = _datetime_to_timestamp(datetime(dt.year, dt.month, dt.day))
#         elif isinstance(dt, float):
#             dt = int(dt)
#         elif isinstance(dt, timedelta):
#             # Timezones are tricky. datetime.utcnow() + ... timestamp() works
#             dt = _datetime_to_timestamp(datetime.utcnow() + dt)
# 
#         if isinstance(dt, int):
#             return struct.pack('<i', dt)
# 
#         raise TypeError('Cannot interpret "{}" as a date.'.format(dt))
# 
#     def __eq__(self, o):
#         return isinstance(o, type(self)) and self.to_dict() == o.to_dict()
# 
#     def __ne__(self, o):
#         return not isinstance(o, type(self)) or self.to_dict() != o.to_dict()
# 
#     def __repr__(self):
#         return pretty_print(self)
# 
#     def __str__(self):
#         return pretty_print(self, max_depth=2)
# 
#     def stringify(self):
#         return pretty_print(self, indent=0)
# 
#     def to_dict(self):
#         res = {}
#         pre = ('', 'fn.')[isinstance(self, TLRequest)]
#         mod = self.__class__.__module__[self.__class__.__module__.rfind('.') + 1:]
#         if mod in ('_tl', 'fn'):
#             res['_'] = f'{pre}{self.__class__.__name__}'
#         else:
#             res['_'] = f'{pre}{mod}.{self.__class__.__name__}'
# 
#         for slot in self.__slots__:
#             attr = getattr(self, slot)
#             if isinstance(attr, list):
#                 res[slot] = [val.to_dict() if hasattr(val, 'to_dict') else val for val in attr]
#             else:
#                 res[slot] = attr.to_dict() if hasattr(attr, 'to_dict') else attr
# 
#         return res
# 
#     def __bytes__(self):
#         try:
#             return self._bytes()
#         except AttributeError:
#             # If a type is wrong (e.g. expected `TLObject` but `int` was
#             # provided) it will try to access `._bytes()`, which will fail
#             # with `AttributeError`. This occurs in fact because the type
#             # was wrong, so raise the correct error type.
#             raise TypeError(f'a TLObject was expected but found {self!r}')
# 
#     # Custom objects will call `(...)._bytes()` and not `bytes(...)` so that
#     # if the wrong type is used (e.g. `int`) we won't try allocating a huge
#     # amount of data, which would cause a `MemoryError`.
#     def _bytes(self):
#         raise NotImplementedError
# 
#     @classmethod
#     def _from_reader(cls, reader):
#         raise NotImplementedError


from .tlmessage import TLMessage
from ..._misc.tlobject import TLObject


class MessageContainer(TLObject):
    CONSTRUCTOR_ID = 0x73f1f8dc

    # Maximum size in bytes for the inner payload of the container.
    # Telegram will close the connection if the payload is bigger.
    # The overhead of the container itself is subtracted.
    MAXIMUM_SIZE = 1044456 - 8

    # Maximum amount of messages that can't be sent inside a single
    # container, inclusive. Beyond this limit Telegram will respond
    # with BAD_MESSAGE 64 (invalid container).
    #
    # This limit is not 100% accurate and may in some cases be higher.
    # However, sending up to 100 requests at once in a single container
    # is a reasonable conservative value, since it could also depend on
    # other factors like size per request, but we cannot know this.
    MAXIMUM_LENGTH = 100

    def __init__(self, messages):
        self.messages = messages

    def to_dict(self):
        return {
            '_': 'MessageContainer',

# Path: telethon/types/_core/tlmessage.py
# class TLMessage(tlobject.TLObject):
#     """
#     https://core.telegram.org/mtproto/service_messages#simple-container.
# 
#     Messages are what's ultimately sent to Telegram:
#         message msg_id:long seqno:int bytes:int body:bytes = Message;
# 
#     Each message has its own unique identifier, and the body is simply
#     the serialized request that should be executed on the server, or
#     the response object from Telegram. Since the body is always a valid
#     object, it makes sense to store the object and not the bytes to
#     ease working with them.
# 
#     There is no need to add serializing logic here since that can be
#     inlined and is unlikely to change. Thus these are only needed to
#     encapsulate responses.
#     """
#     SIZE_OVERHEAD = 12
# 
#     def __init__(self, msg_id, seq_no, obj):
#         self.msg_id = msg_id
#         self.seq_no = seq_no
#         self.obj = obj
# 
#     def to_dict(self):
#         return {
#             '_': 'TLMessage',
#             'msg_id': self.msg_id,
#             'seq_no': self.seq_no,
#             'obj': self.obj
#         }
# 
# Path: telethon/_misc/tlobject.py
# class TLObject:
#     __slots__ = ()
#     CONSTRUCTOR_ID = None
#     SUBCLASS_OF_ID = None
# 
#     @staticmethod
#     def _serialize_bytes(data):
#         """Write bytes by using Telegram guidelines"""
#         if not isinstance(data, bytes):
#             if isinstance(data, str):
#                 data = data.encode('utf-8')
#             else:
#                 raise TypeError(
#                     'bytes or str expected, not {}'.format(type(data)))
# 
#         r = []
#         if len(data) < 254:
#             padding = (len(data) + 1) % 4
#             if padding != 0:
#                 padding = 4 - padding
# 
#             r.append(bytes([len(data)]))
#             r.append(data)
# 
#         else:
#             padding = len(data) % 4
#             if padding != 0:
#                 padding = 4 - padding
# 
#             r.append(bytes([
#                 254,
#                 len(data) % 256,
#                 (len(data) >> 8) % 256,
#                 (len(data) >> 16) % 256
#             ]))
#             r.append(data)
# 
#         r.append(bytes(padding))
#         return b''.join(r)
# 
#     @staticmethod
#     def _serialize_datetime(dt):
#         if not dt and not isinstance(dt, timedelta):
#             return b'\0\0\0\0'
# 
#         if isinstance(dt, datetime):
#             dt = _datetime_to_timestamp(dt)
#         elif isinstance(dt, date):
#             dt = _datetime_to_timestamp(datetime(dt.year, dt.month, dt.day))
#         elif isinstance(dt, float):
#             dt = int(dt)
#         elif isinstance(dt, timedelta):
#             # Timezones are tricky. datetime.utcnow() + ... timestamp() works
#             dt = _datetime_to_timestamp(datetime.utcnow() + dt)
# 
#         if isinstance(dt, int):
#             return struct.pack('<i', dt)
# 
#         raise TypeError('Cannot interpret "{}" as a date.'.format(dt))
# 
#     def __eq__(self, o):
#         return isinstance(o, type(self)) and self.to_dict() == o.to_dict()
# 
#     def __ne__(self, o):
#         return not isinstance(o, type(self)) or self.to_dict() != o.to_dict()
# 
#     def __repr__(self):
#         return pretty_print(self)
# 
#     def __str__(self):
#         return pretty_print(self, max_depth=2)
# 
#     def stringify(self):
#         return pretty_print(self, indent=0)
# 
#     def to_dict(self):
#         res = {}
#         pre = ('', 'fn.')[isinstance(self, TLRequest)]
#         mod = self.__class__.__module__[self.__class__.__module__.rfind('.') + 1:]
#         if mod in ('_tl', 'fn'):
#             res['_'] = f'{pre}{self.__class__.__name__}'
#         else:
#             res['_'] = f'{pre}{mod}.{self.__class__.__name__}'
# 
#         for slot in self.__slots__:
#             attr = getattr(self, slot)
#             if isinstance(attr, list):
#                 res[slot] = [val.to_dict() if hasattr(val, 'to_dict') else val for val in attr]
#             else:
#                 res[slot] = attr.to_dict() if hasattr(attr, 'to_dict') else attr
# 
#         return res
# 
#     def __bytes__(self):
#         try:
#             return self._bytes()
#         except AttributeError:
#             # If a type is wrong (e.g. expected `TLObject` but `int` was
#             # provided) it will try to access `._bytes()`, which will fail
#             # with `AttributeError`. This occurs in fact because the type
#             # was wrong, so raise the correct error type.
#             raise TypeError(f'a TLObject was expected but found {self!r}')
# 
#     # Custom objects will call `(...)._bytes()` and not `bytes(...)` so that
#     # if the wrong type is used (e.g. `int`) we won't try allocating a huge
#     # amount of data, which would cause a `MemoryError`.
#     def _bytes(self):
#         raise NotImplementedError
# 
#     @classmethod
#     def _from_reader(cls, reader):
#         raise NotImplementedError


# Path: telethon/types/_core/messagecontainer.py
from .tlmessage import TLMessage
from ..._misc.tlobject import TLObject



class MessageContainer(TLObject):
    CONSTRUCTOR_ID = 0x73f1f8dc

    # Maximum size in bytes for the inner payload of the container.
    # Telegram will close the connection if the payload is bigger.
    # The overhead of the container itself is subtracted.
    MAXIMUM_SIZE = 1044456 - 8

    # Maximum amount of messages that can't be sent inside a single
    # container, inclusive. Beyond this limit Telegram will respond
    # with BAD_MESSAGE 64 (invalid container).
    #
    # This limit is not 100% accurate and may in some cases be higher.
    # However, sending up to 100 requests at once in a single container
    # is a reasonable conservative value, since it could also depend on
    # other factors like size per request, but we cannot know this.
    MAXIMUM_LENGTH = 100

    def __init__(self, messages):
        self.messages = messages

    def to_dict(self):
        return {
            '_': 'MessageContainer',

            'messages':