from telethon.tl.mtproto_request import MTProtoRequest


class RpcError(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    rpc_error#2144ca19 error_code:int error_message:string = RpcError"""

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

    def __init__(self, error_code, error_message):
        """
        :param error_code: Telegram type: «int».
        :param error_message: Telegram type: «string».
        """
        super().__init__()

        self.error_code = error_code
        self.error_message = error_message

    def on_send(self, writer):
        writer.write_int(RpcError.constructor_id, signed=False)
        writer.write_int(self.error_code)
        writer.tgwrite_string(self.error_message)

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

    def on_response(self, reader):
        self.error_code = reader.read_int()
        self.error_message = reader.tgread_string()

    def __repr__(self):
        return 'rpc_error#2144ca19 error_code:int error_message:string = RpcError'

    def __str__(self):
        return '(rpc_error (ID: 0x2144ca19) = (error_code={}, error_message={}))'.format(str(self.error_code), str(self.error_message))
