import aps2.utils
import aps2.parameter


class FunctionDescription(object):
    def __init__(self, json, call_name):
        self.json = json
        self.call_name = call_name


class FunctionCaller(object):
    def __init__(self,
                 parsed_environ,
                 controller_client,
                 service_description,
                 function_description
                 ):
        application_object = aps2.utils.load_application_object(
            parsed_environ,
            controller_client,
            service_description,
            function_description
        )
        self.method = getattr(application_object, function_description.call_name)

    def call(self, parsed_environ, arguments):
        self.method(*arguments)
        num_response = '204 OK' if parsed_environ.get("REQUEST_METHOD") == "DELETE" else '200 OK'
        type_response = [('Content-type', 'text/plain')]  # TODO fix
        function_result = "{}"  # TODO Fix
        return num_response, type_response, function_result

