from typing import List

from evowluator.data.ontology import Syntax
from evowluator.reasoner.base import MetaArgs, Reasoner, ReasoningTask, OutputFormat
from evowluator.evaluation.mode import EvaluationMode
from .owlapi import OWLAPIReasoner


class MiniMEJava(OWLAPIReasoner):
    """MiniME Java reasoner wrapper."""

    @property
    def name(self) -> str:
        return 'Mini-ME Java'

    @property
    def path(self) -> str:
        return 'MiniMEJava/minimecli.jar'

    @property
    def supported_tasks(self) -> List[ReasoningTask]:
        return ReasoningTask.all()

    def args(self, task: ReasoningTask, mode: EvaluationMode) -> List[str]:
        if task == ReasoningTask.MATCHMAKING:
            return ['abduction-contraction', '-r', MetaArgs.REQUEST, MetaArgs.INPUT]
        else:
            return super().args(task, mode)


class MiniMESwift(Reasoner):
    """MiniME Swift reasoner wrapper."""

    @property
    def name(self) -> str:
        return 'Mini-ME Swift'

    @property
    def path(self) -> str:
        return 'MiniMESwift/MiniME-cli'

    @property
    def supported_syntaxes(self) -> List[Syntax]:
        return [Syntax.RDFXML]

    @property
    def supported_tasks(self) -> List[ReasoningTask]:
        return ReasoningTask.all()

    @property
    def classification_output_format(self) -> OutputFormat:
        return OutputFormat.TEXT

    def args(self, task: ReasoningTask, mode: EvaluationMode) -> List[str]:
        if task == ReasoningTask.CLASSIFICATION:
            args = ['classification', '-i', MetaArgs.INPUT]
        elif task == ReasoningTask.CONSISTENCY:
            args = ['consistency', '-i', MetaArgs.INPUT]
        else:
            args = ['abduction-contraction', '-i', MetaArgs.INPUT, '-r', MetaArgs.REQUEST]

        if task != ReasoningTask.CONSISTENCY and mode == EvaluationMode.CORRECTNESS:
            args.extend(['-o', MetaArgs.OUTPUT])

        return args
