from ...tl.mtproto_request import MTProtoRequest


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

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

    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 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 (all attributes are 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 '(phoneConnection (ID: 0x9d4c17c0) = (id={}, ip={}, ipv6={}, port={}, peer_tag={}))'.format(str(self.id), str(self.ip), str(self.ipv6), str(self.port), str(self.peer_tag))
