# Checker.py -- Pamhyr abstract checker class
# Copyright (C) 2023  INRAE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

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

from enum import Enum

from Model.Except import NotImplementedMethodeError


class STATUS(Enum):
    UNKNOWN = -1
    OK = 0
    WARNING = 1
    ERROR = 2


class AbstractModelChecker(object):
    def __init__(self):
        self._name = ""
        self._description = ""

        self._status = STATUS.UNKNOWN
        self._summary = "Unknown"

    @property
    def name(self):
        return self._name

    @property
    def description(self):
        return self._description

    @property
    def summary(self):
        return self._summary

    # Checker status

    def is_unknown(self):
        return self._status == STATUS.UNKNOWN

    def is_ok(self):
        return self._status == STATUS.OK

    def is_warning(self):
        return self._status == STATUS.WARNING

    def is_error(self):
        return self._status == STATUS.ERROR

    # Abstract function

    def _run(self, study):
        from Model.Study import Study

        thread_study = Study.open(study._filename)
        self.run(thread_study)

    def run(self, study):
        """Run checker function

        Args:
            study: The study to check

        Returns:
            Return true if study is valid for this checker, false
            otherelse
        """
        raise NotImplementedMethodeError(self, self.run)
