"""@ingroup default_suites
@file
Contains the quality suite definitions necessary for doxygen enforcement.
"""
from vigilance.configuration import ConfigurationStanza
from vigilance.constraint import Constraint
from vigilance.parser import Parser
from vigilance.plugin import AbstractPlugin, SuiteComponents
from vigilance.representation import QualityItem, QualityReport, Satisfaction

class DocumentationError(QualityItem):
    """Represents a single documentation error from a Doxygen run.
    """
    @property
    def identifier(self):
        return 'documentation failure: {}'.format(self.metrics)

class DoxygenParser(Parser):
    """A Parser implementation for Doxygen error reports.
    These reports should be generated by redirecting stderr from the doxygen command to a file.
    """
    def parse(self, fileContents):
        docErrors = [DocumentationError(line) for line in fileContents.split('\n') if line]
        return QualityReport(docErrors)

class Documentation(Constraint):
    """A Constraint that enforces documentation.
    """
    def satisfied_by(self, item):
        return Satisfaction(False, item.identifier)

class DocumentationStanza(ConfigurationStanza):
    """The documentation configuration stanza.
    """
    def parse(self, stanza):
        return [Documentation()]

class Default(AbstractPlugin):
    """The AbstractPlugin implementation for doxygen.
    """
    def get_suite_components(self):
        return SuiteComponents('doxygen',
                               DoxygenParser(),
                               {'documentation': Documentation},
                               {'documentation': DocumentationStanza})
