from Matching.AbstractMatcher import AbstractMatcher
from Models.UserModel import UserModel


class PreferenceMatcher(AbstractMatcher):

    def __init__(self, preferences, user):
        self.preferences = preferences
        self.user = user
        self.metric = None
        super().__init__(user)

    def get_metric(self):
        if not self.metric:
            umf = self._get_umf(self.preferences)
            project = umf.create_project_metric()
            interests = umf.create_interests_metric()
            age_group = umf.create_age_group_metric()
            liked_back = umf.create_liked_back_metric()
            has_matches = umf.create_has_matches_metric()
            is_inactive = umf.create_is_inactive_metric()

            self.metric = project + age_group + interests
            # liked back bonus
            self.metric += self.metric * liked_back * 0.3
            # has a lot of matches already penalty
            self.metric *= has_matches
            # was recently active
            self.metric *= is_inactive

        return self.metric

    def query_users(self):
        # system user is filtered out in SuperClass
        return UserModel.query.filter(UserModel.id != self.user.id).all()
