"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 25.10.21

"""
from abc import abstractmethod
from django.utils.translation import  gettext_lazy as _

from konova.models import BaseObject


class AbstractQualityChecker:
    valid = False
    messages = []
    obj = None

    class Meta:
        abstract = True

    def __init__(self, obj: BaseObject):
        self.obj = obj
        self.messages = []
        self.valid = False

    @abstractmethod
    def run_check(self):
        raise NotImplementedError

    def _add_missing_attr_name(self, attr_name: str):
        missing = _('missing')
        self.messages.append(f"{attr_name} {missing}")

    def _check_geometry(self):
        """ Checks on the geometry

        Returns:

        """
        try:
            geometry_obj = self.obj.geometry
            if geometry_obj.geom.empty:
                self._add_missing_attr_name(_("Geometry"))
        except AttributeError:
            self._add_missing_attr_name(_("Geometry"))
