# -*- coding: utf-8 -*-
"""
This file is part of checkmate, a meta code checker written in Python.

Copyright (C) 2015 Andreas Dewes, QuantifiedCode UG

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

from __future__ import unicode_literals
import abc

class BaseAnalyzer(object):

    """
    This abstract base class defines an analyzer, which takes file content and produces
    statistics as well as a list of issues. It is also responsible for diffing statistical
    data and issues obtained for different file revisions or snapshots.
    """

    def __init__(self,code_environment,params = None,ignore = None):
        self.code_environment = code_environment
        self.params = params
        if ignore is not None:
            self.ignore = {}
            for code in ignore:
                self.ignore[code] = True

    @abc.abstractmethod
    def analyze(self,file_revision):
        """
        Analyze a file and return a tuple (stats,issues) containing statistics and issues.

        This method should return a dictionary with one of the following entries:

        * issues: A list of issues found in the file revision
        * stats: Statistics about the file revision
        * depends_on: A list of dependencies for the file revision
        * provides: A list of things the file revision provides (e.g. a module),
                    to be used with the `depends_on` field.
        """
        pass

    def diff(self,results_a,results_b):
        pass

    def diff_summary(self,summary_a,summary_b):
        pass

    @abc.abstractmethod
    def summarize(self,items):
        """
        Aggregate a list of items containing statistical information generated by 'analyze'.
        """
        pass

