"""
ML Autogen
==========

This is an autogenerated file DO NOT TOUCH, it's sole intention is to provide IDEs
a way to index functions and thereby supporting the users with autocompletion.

Generated by: autogen.py
Complements: on_ml.py

Time of generation (UTC): {{timestamp}}
"""
# -----------------------------------------------------------------------------------

# The classes here are designed like gRPC stubs, templates that can be indexed by the
# IDE and intuitively used by the users by just filling the variable in it.

from typing import Union, Any
from google.protobuf.timestamp_pb2 import Timestamp

from .model_spec_pb2 import ModelSpec, Framework
from .on_ml import NboxOptions
{%for (data, frm, cond_fn) in frameworks%}
# --------- {{frm}} --------- #
{%for item in data.messages%}
class {{item.message_name}}:
  # @isthere("{{item.dependencies|join('","')}}", soft=False)
  def __init__(
    self,
    {{item.arg_strings|join(',\n')|indent(4)}},
    **kwargs
  ):
    '''AUTOGENERATED by ``nbox``, some arguments might be missing, USE ``kwargs`` CAREFULLY!

    {{item.doc|indent(4)}}
    '''
    {%for arg in item.args%}self.{{arg}}={{arg}}
    {%endfor%}
    for k,v in kwargs.items():
      setattr(self, k, v)
{%endfor%}

class Framework_{{frm}}:
  _load_framework="{{frm}}"
  def _conditional(py_model):
    from .on_ml import {{cond_fn}}
    return {{cond_fn}}(py_model)
  {%for fn in data.stubs%}
  # @isthere("{{fn.dependencies|join('","')}}", soft=False)
  def {{fn.stub_name}}(user_options: {{fn.message_name}}, nbox_options: NboxOptions) -> Union[ModelSpec, Any]:
    '''
    Args:
      user_options (nbox.framework.ml.{{fn.message_name}}): Variables to be filled by the user
      _nbox_options (nbox.framework.NboxOptions): Options to be used by NBX-Services
    Returns:
      when serialising the model returns ``ModelSpec`` else returns the ``model`` in ``nbox.Model``
    '''
    from .on_ml import {{fn.processor_fn}}
    exported_time = Timestamp(); exported_time.GetCurrentTime()
    spec=ModelSpec(
      source=Framework(package="{{frm}}", method="Framework_{{frm}}.{{fn.stub_name}}"),
      {%if fn.target_processor_name%}target=Framework(package="{{fn.target}}", method="Framework_{{fn.target}}.{{fn.target_processor_name}}"),{%else%}target=None, # this function has not been defined to throw any output{%endif%}
      folder=nbox_options.folder,
      name=nbox_options.model_name,
      requirements=["{{fn.dependencies|join('","')}}"], # contents inside requirements.txt file
      exported_time=exported_time,
      inputs=[],
      outputs=[],
    )
    spec={{fn.processor_fn}}(user_options, nbox_options, spec) # spec can be updated by the function
    return spec
  {%endfor%}
  _METHODS={
    {%for fn in data.stubs%}'{{fn.stub_name}}': ({{fn.stub_name}}, {{fn.message_name}}),
    {%endfor%}}
{%endfor%}

# End of file
