from .BaseColumnCheck import BaseColumnCheck
from .Functions import Functions


class CheckColumnLikeAll(BaseColumnCheck):
    ##################################################################################################
    # Constructor
    ##################################################################################################
    def __init__(self, id, column_name, column_like, match=True):
        BaseColumnCheck.__init__(self, id, column_name)
        self.column_like = column_like
        self.settings["column_like"] = self.column_like

        self.column_regex = Functions.like_2_regex(self.column_like)
        self.settings["column_regex"] = self.column_regex
        
        self.match = match
        self.settings["match"] = self.match
        if match:
            self.column_function = Functions.check_column_match_regex
        else:
            self.column_function = Functions.check_column_not_match_regex

    ##################################################################################################
    # Methods
    ##################################################################################################
    def _run(self, dataset):
        passed = self._column_function(dataset, self.column_name, self.column_regex).all()
        match_message = "match"
        if self.match == False:
            match_message = "don't match"
        message = f"All values in column '{self.column_name}' {match_message} the given regex pattern '{self.column_regex}'!"
        if not passed:
            message = f"Not all values in column '{self.column_name}' {match_message} the given regex pattern '{self.column_regex}'!"
        return passed, message

    ##################################################################################################
    # Properties
    ##################################################################################################
    @property
    def column_function(self):
        return self._column_function

    @column_function.setter
    def column_function(self, value):
        self._column_function = value

    @property
    def column_function_str(self):
        desc = Functions.get_string(self.column_function)
        return desc

    @property
    def column_regex(self):
        return self._column_regex

    @column_regex.setter
    def column_regex(self, value):
        self._column_regex = value

    @property
    def column_like(self):
        return self._column_like

    @column_like.setter
    def column_like(self, value):
        self._column_like = value

    @property
    def match(self):
        return self._match

    @match.setter
    def match(self, value):
        self._match = value
