from ...tl.mtproto_request import MTProtoRequest


class Config(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    config#cb601684 flags:# phonecalls_enabled:flags.1?true date:date expires:date test_mode:Bool this_dc:int dc_options:Vector<DcOption> chat_size_max:int megagroup_size_max:int forwarded_count_max:int online_update_period_ms:int offline_blur_timeout_ms:int offline_idle_timeout_ms:int online_cloud_timeout_ms:int notify_cloud_delay_ms:int notify_default_delay_ms:int chat_big_size:int push_chat_period_ms:int push_chat_limit:int saved_gifs_limit:int edit_time_limit:int rating_e_decay:int stickers_recent_limit:int tmp_sessions:flags.0?int pinned_dialogs_count_max:int call_receive_timeout_ms:int call_ring_timeout_ms:int call_connect_timeout_ms:int call_packet_timeout_ms:int me_url_prefix:string disabled_features:Vector<DisabledFeature> = Config"""

    # Telegram's constructor ID (and unique identifier) for this class
    constructor_id = 0xcb601684

    def __init__(self, date, expires, test_mode, this_dc, dc_options, chat_size_max, megagroup_size_max, forwarded_count_max, online_update_period_ms, offline_blur_timeout_ms, offline_idle_timeout_ms, online_cloud_timeout_ms, notify_cloud_delay_ms, notify_default_delay_ms, chat_big_size, push_chat_period_ms, push_chat_limit, saved_gifs_limit, edit_time_limit, rating_e_decay, stickers_recent_limit, pinned_dialogs_count_max, call_receive_timeout_ms, call_ring_timeout_ms, call_connect_timeout_ms, call_packet_timeout_ms, me_url_prefix, disabled_features, phonecalls_enabled=None, tmp_sessions=None):
        """
        :param phonecalls_enabled: Telegram type: «true».
        :param date: Telegram type: «date».
        :param expires: Telegram type: «date».
        :param test_mode: Telegram type: «Bool».
        :param this_dc: Telegram type: «int».
        :param dc_options: Telegram type: «DcOption». Must be a list.
        :param chat_size_max: Telegram type: «int».
        :param megagroup_size_max: Telegram type: «int».
        :param forwarded_count_max: Telegram type: «int».
        :param online_update_period_ms: Telegram type: «int».
        :param offline_blur_timeout_ms: Telegram type: «int».
        :param offline_idle_timeout_ms: Telegram type: «int».
        :param online_cloud_timeout_ms: Telegram type: «int».
        :param notify_cloud_delay_ms: Telegram type: «int».
        :param notify_default_delay_ms: Telegram type: «int».
        :param chat_big_size: Telegram type: «int».
        :param push_chat_period_ms: Telegram type: «int».
        :param push_chat_limit: Telegram type: «int».
        :param saved_gifs_limit: Telegram type: «int».
        :param edit_time_limit: Telegram type: «int».
        :param rating_e_decay: Telegram type: «int».
        :param stickers_recent_limit: Telegram type: «int».
        :param tmp_sessions: Telegram type: «int».
        :param pinned_dialogs_count_max: Telegram type: «int».
        :param call_receive_timeout_ms: Telegram type: «int».
        :param call_ring_timeout_ms: Telegram type: «int».
        :param call_connect_timeout_ms: Telegram type: «int».
        :param call_packet_timeout_ms: Telegram type: «int».
        :param me_url_prefix: Telegram type: «string».
        :param disabled_features: Telegram type: «DisabledFeature». Must be a list.

        Constructor for Config: Instance of Config.
        """
        super().__init__()

        self.phonecalls_enabled = phonecalls_enabled
        self.date = date
        self.expires = expires
        self.test_mode = test_mode
        self.this_dc = this_dc
        self.dc_options = dc_options
        self.chat_size_max = chat_size_max
        self.megagroup_size_max = megagroup_size_max
        self.forwarded_count_max = forwarded_count_max
        self.online_update_period_ms = online_update_period_ms
        self.offline_blur_timeout_ms = offline_blur_timeout_ms
        self.offline_idle_timeout_ms = offline_idle_timeout_ms
        self.online_cloud_timeout_ms = online_cloud_timeout_ms
        self.notify_cloud_delay_ms = notify_cloud_delay_ms
        self.notify_default_delay_ms = notify_default_delay_ms
        self.chat_big_size = chat_big_size
        self.push_chat_period_ms = push_chat_period_ms
        self.push_chat_limit = push_chat_limit
        self.saved_gifs_limit = saved_gifs_limit
        self.edit_time_limit = edit_time_limit
        self.rating_e_decay = rating_e_decay
        self.stickers_recent_limit = stickers_recent_limit
        self.tmp_sessions = tmp_sessions
        self.pinned_dialogs_count_max = pinned_dialogs_count_max
        self.call_receive_timeout_ms = call_receive_timeout_ms
        self.call_ring_timeout_ms = call_ring_timeout_ms
        self.call_connect_timeout_ms = call_connect_timeout_ms
        self.call_packet_timeout_ms = call_packet_timeout_ms
        self.me_url_prefix = me_url_prefix
        self.disabled_features = disabled_features

    def on_send(self, writer):
        writer.write_int(Config.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 1) if self.phonecalls_enabled else 0
        flags |= (1 << 0) if self.tmp_sessions else 0
        writer.write_int(flags)

        writer.tgwrite_date(self.date)
        writer.tgwrite_date(self.expires)
        writer.tgwrite_bool(self.test_mode)
        writer.write_int(self.this_dc)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.dc_options))
        for dc_options_item in self.dc_options:
            dc_options_item.on_send(writer)

        writer.write_int(self.chat_size_max)
        writer.write_int(self.megagroup_size_max)
        writer.write_int(self.forwarded_count_max)
        writer.write_int(self.online_update_period_ms)
        writer.write_int(self.offline_blur_timeout_ms)
        writer.write_int(self.offline_idle_timeout_ms)
        writer.write_int(self.online_cloud_timeout_ms)
        writer.write_int(self.notify_cloud_delay_ms)
        writer.write_int(self.notify_default_delay_ms)
        writer.write_int(self.chat_big_size)
        writer.write_int(self.push_chat_period_ms)
        writer.write_int(self.push_chat_limit)
        writer.write_int(self.saved_gifs_limit)
        writer.write_int(self.edit_time_limit)
        writer.write_int(self.rating_e_decay)
        writer.write_int(self.stickers_recent_limit)
        if self.tmp_sessions:
            writer.write_int(self.tmp_sessions)

        writer.write_int(self.pinned_dialogs_count_max)
        writer.write_int(self.call_receive_timeout_ms)
        writer.write_int(self.call_ring_timeout_ms)
        writer.write_int(self.call_connect_timeout_ms)
        writer.write_int(self.call_packet_timeout_ms)
        writer.tgwrite_string(self.me_url_prefix)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.disabled_features))
        for disabled_features_item in self.disabled_features:
            disabled_features_item.on_send(writer)

    @staticmethod
    def empty():
        """Returns an "empty" instance (all attributes are None)"""
        return Config(None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None)

    def on_response(self, reader):
        flags = reader.read_int()

        if (flags & (1 << 1)) != 0:
            self.phonecalls_enabled = True  # Arbitrary not-None value, no need to read since it is a flag

        self.date = reader.tgread_date()
        self.expires = reader.tgread_date()
        self.test_mode = reader.tgread_bool()
        self.this_dc = reader.read_int()
        reader.read_int()  # Vector's constructor ID
        self.dc_options = []  # Initialize an empty list
        dc_options_len = reader.read_int()
        for _ in range(dc_options_len):
            dc_options_item = reader.tgread_object()
            self.dc_options.append(dc_options_item)

        self.chat_size_max = reader.read_int()
        self.megagroup_size_max = reader.read_int()
        self.forwarded_count_max = reader.read_int()
        self.online_update_period_ms = reader.read_int()
        self.offline_blur_timeout_ms = reader.read_int()
        self.offline_idle_timeout_ms = reader.read_int()
        self.online_cloud_timeout_ms = reader.read_int()
        self.notify_cloud_delay_ms = reader.read_int()
        self.notify_default_delay_ms = reader.read_int()
        self.chat_big_size = reader.read_int()
        self.push_chat_period_ms = reader.read_int()
        self.push_chat_limit = reader.read_int()
        self.saved_gifs_limit = reader.read_int()
        self.edit_time_limit = reader.read_int()
        self.rating_e_decay = reader.read_int()
        self.stickers_recent_limit = reader.read_int()
        if (flags & (1 << 0)) != 0:
            self.tmp_sessions = reader.read_int()

        self.pinned_dialogs_count_max = reader.read_int()
        self.call_receive_timeout_ms = reader.read_int()
        self.call_ring_timeout_ms = reader.read_int()
        self.call_connect_timeout_ms = reader.read_int()
        self.call_packet_timeout_ms = reader.read_int()
        self.me_url_prefix = reader.tgread_string()
        reader.read_int()  # Vector's constructor ID
        self.disabled_features = []  # Initialize an empty list
        disabled_features_len = reader.read_int()
        for _ in range(disabled_features_len):
            disabled_features_item = reader.tgread_object()
            self.disabled_features.append(disabled_features_item)

    def __repr__(self):
        return 'config#cb601684 flags:# phonecalls_enabled:flags.1?true date:date expires:date test_mode:Bool this_dc:int dc_options:Vector<DcOption> chat_size_max:int megagroup_size_max:int forwarded_count_max:int online_update_period_ms:int offline_blur_timeout_ms:int offline_idle_timeout_ms:int online_cloud_timeout_ms:int notify_cloud_delay_ms:int notify_default_delay_ms:int chat_big_size:int push_chat_period_ms:int push_chat_limit:int saved_gifs_limit:int edit_time_limit:int rating_e_decay:int stickers_recent_limit:int tmp_sessions:flags.0?int pinned_dialogs_count_max:int call_receive_timeout_ms:int call_ring_timeout_ms:int call_connect_timeout_ms:int call_packet_timeout_ms:int me_url_prefix:string disabled_features:Vector<DisabledFeature> = Config'

    def __str__(self):
        return '(config (ID: 0xcb601684) = (phonecalls_enabled={}, date={}, expires={}, test_mode={}, this_dc={}, dc_options={}, chat_size_max={}, megagroup_size_max={}, forwarded_count_max={}, online_update_period_ms={}, offline_blur_timeout_ms={}, offline_idle_timeout_ms={}, online_cloud_timeout_ms={}, notify_cloud_delay_ms={}, notify_default_delay_ms={}, chat_big_size={}, push_chat_period_ms={}, push_chat_limit={}, saved_gifs_limit={}, edit_time_limit={}, rating_e_decay={}, stickers_recent_limit={}, tmp_sessions={}, pinned_dialogs_count_max={}, call_receive_timeout_ms={}, call_ring_timeout_ms={}, call_connect_timeout_ms={}, call_packet_timeout_ms={}, me_url_prefix={}, disabled_features={}))'.format(str(self.phonecalls_enabled), str(self.date), str(self.expires), str(self.test_mode), str(self.this_dc), None if not self.dc_options else [str(_) for _ in self.dc_options], str(self.chat_size_max), str(self.megagroup_size_max), str(self.forwarded_count_max), str(self.online_update_period_ms), str(self.offline_blur_timeout_ms), str(self.offline_idle_timeout_ms), str(self.online_cloud_timeout_ms), str(self.notify_cloud_delay_ms), str(self.notify_default_delay_ms), str(self.chat_big_size), str(self.push_chat_period_ms), str(self.push_chat_limit), str(self.saved_gifs_limit), str(self.edit_time_limit), str(self.rating_e_decay), str(self.stickers_recent_limit), str(self.tmp_sessions), str(self.pinned_dialogs_count_max), str(self.call_receive_timeout_ms), str(self.call_ring_timeout_ms), str(self.call_connect_timeout_ms), str(self.call_packet_timeout_ms), str(self.me_url_prefix), None if not self.disabled_features else [str(_) for _ in self.disabled_features])
