# Auto generated file. DO NOT EDIT.

import requests
from functools import partial
{%for _import in imports_strings%}
{{_import}}{%endfor%}

from yql.rest_pb2 import Echo
from yql.common import *


# ------ Stub ------ #

class {{service_name}}_Stub:
  def __init__(self, url: str, session: requests.Session = None):
    self.url = url.rstrip("/")
    self.session = session or requests.Session()
    self.status = partial(call_rpc, sess = self.session, url = f"{url}/")
    self.protos = partial(call_rpc, sess = self.session, url = f"{url}/protos")
{%for (_rpc, _in_var, _input_proto, _out_var, _output_proto) in service_tuples%}
  def {{_rpc}}(self, {{_in_var}}: {{_input_proto}}) -> {{_output_proto}}:
    echo_resp: Echo = call_rpc(
      self.session,
      f"{self.url}/predict",
      Echo(message = "{{_input_proto}}", base64_string=message_to_b64({{_in_var}}), rpc_name = "{{_rpc}}")
    )

    if echo_resp.base64_string == "":
      # something else happened and we don't have a proto_data, so print the message
      print("\n> Server side error:")
      for l in echo_resp.message.splitlines():
        print(l)
      print("\n")
      return None
    
    {{_out_var}} = {{_output_proto}}() # predefine the output proto
    {{_out_var}} = b64_to_message(echo_resp.base64_string, {{_out_var}})
    return {{_out_var}}
{%endfor%}

# ------ End Stub ------ #