from ...tl.mtproto_request import MTProtoRequest


class IpPort(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    ipPort#d433ad73 ipv4:int port:int = IpPort"""

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

    def __init__(self, ipv4, port):
        """
        :param ipv4: Telegram type: "int".
        :param port: Telegram type: "int".

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

        self.ipv4 = ipv4
        self.port = port

    def to_dict(self):
        return {
            'ipv4': self.ipv4,
            'port': self.port,
        }

    def on_send(self, writer):
        writer.write_int(IpPort.constructor_id, signed=False)
        writer.write_int(self.ipv4)
        writer.write_int(self.port)

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

    def on_response(self, reader):
        self.ipv4 = reader.read_int()
        self.port = reader.read_int()

    def __repr__(self):
        return 'ipPort#d433ad73 ipv4:int port:int = IpPort'

    def __str__(self):
        return '(ipPort (ID: 0xd433ad73) = (ipv4={}, port={}))'.format(str(self.ipv4), str(self.port))
