from ...tl.tlobject import TLObject


class PhoneConnection(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    phoneConnection#9d4c17c0 id:long ip:string ipv6:string port:int peer_tag:bytes = PhoneConnection"""

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

    def __init__(self, id, ip, ipv6, port, peer_tag):
        """
        :param id: Telegram type: "long".
        :param ip: Telegram type: "string".
        :param ipv6: Telegram type: "string".
        :param port: Telegram type: "int".
        :param peer_tag: Telegram type: "bytes".

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

        self.id = id
        self.ip = ip
        self.ipv6 = ipv6
        self.port = port
        self.peer_tag = peer_tag

    def to_dict(self):
        return {
            'id': self.id,
            'ip': self.ip,
            'ipv6': self.ipv6,
            'port': self.port,
            'peer_tag': self.peer_tag,
        }

    def on_send(self, writer):
        writer.write_int(PhoneConnection.constructor_id, signed=False)
        writer.write_long(self.id)
        writer.tgwrite_string(self.ip)
        writer.tgwrite_string(self.ipv6)
        writer.write_int(self.port)
        writer.tgwrite_bytes(self.peer_tag)

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

    def on_response(self, reader):
        self.id = reader.read_long()
        self.ip = reader.tgread_string()
        self.ipv6 = reader.tgread_string()
        self.port = reader.read_int()
        self.peer_tag = reader.tgread_bytes()

    def __repr__(self):
        return 'phoneConnection#9d4c17c0 id:long ip:string ipv6:string port:int peer_tag:bytes = PhoneConnection'

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

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