from ....tl.tlobject import TLObject


class ConfigSimple(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    help.configSimple#d997c3c5 date:int expires:int dc_id:int ip_port_list:Vector<ipPort> = help.ConfigSimple"""

    # Telegram's constructor (U)ID for this class
    constructor_id = 0xd997c3c5
    # Also the ID of its resulting type for fast checks
    subclass_of_id = 0x29183ac4

    def __init__(self, date, expires, dc_id, ip_port_list):
        """
        :param date: Telegram type: "date".
        :param expires: Telegram type: "date".
        :param dc_id: Telegram type: "int".
        :param ip_port_list: Telegram type: "ipPort". Must be a list.

        Constructor for help.ConfigSimple: Instance of ConfigSimple.
        """
        super().__init__()

        self.date = date
        self.expires = expires
        self.dc_id = dc_id
        self.ip_port_list = ip_port_list

    def to_dict(self):
        return {
            'date': self.date,
            'expires': self.expires,
            'dc_id': self.dc_id,
            'ip_port_list': [] if self.ip_port_list is None else [None if x is None else x.to_dict() for x in self.ip_port_list],
        }

    def on_send(self, writer):
        writer.write_int(ConfigSimple.constructor_id, signed=False)
        writer.tgwrite_date(self.date)
        writer.tgwrite_date(self.expires)
        writer.write_int(self.dc_id)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.ip_port_list))
        for _x in self.ip_port_list:
            _x.on_send(writer)

    @staticmethod
    def empty():
        """Returns an "empty" instance (attributes=None)"""
        return ConfigSimple(None, None, None, None)

    def on_response(self, reader):
        self.date = reader.tgread_date()
        self.expires = reader.tgread_date()
        self.dc_id = reader.read_int()
        reader.read_int()  # Vector's constructor ID
        self.ip_port_list = []  # Initialize an empty list
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.ip_port_list.append(_x)

    def __repr__(self):
        return 'help.configSimple#d997c3c5 date:int expires:int dc_id:int ip_port_list:Vector<ipPort> = help.ConfigSimple'

    def __str__(self):
        return TLObject.pretty_format(self)

    def stringify(self):
        return TLObject.pretty_format(self, indent=0)
