# -*- coding: utf-8 -*-

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import

from .logging           import *
from .arguments_manager import *
from .context           import *


class GenericTask(ArgumentsManagerMixin):
    __metaclass__ = ArgumentsManagerMeta

    args_types = {}

    def init_context(self):
        assert(self._context)
        return

    def set_context(self, context):
        assert(context)
        self._context = context

    @property
    def context(self):
        assert(self._context)
        return self._context

    def input(self):
        return None

    def output(self):
        return None

    def dependencies(self):
        return None

    def run(self):
        raise NotImplementedError("run")

    on_incomplete_requirements = None

    on_run_failure = None

    def __repr__(self):
        return "<Task: {}>".format(self.__str__())

    def __str__(self):
        args = [
            str(k) + "=" + str(self.args[k])
            for k in get_managed_args(self.__class__).iterkeys()
        ]
        return "{}({})".format(self.__class__.__name__, ", ".join(args))
