from Models.MatchingPreferencesModel import MatchingPreferencesModel
from Models.UserModel import UserModel
from Matching.PreferenceTyps import *
import Matching.Metrics as Metrics
import Matching.MetaMetrics as MetaMetrics


class UserMetricFactory:
    """
    returns metric objects according to specifications in PreferenceData-object
    """

    """
    User configurable Metrics
    """

    def __init__(self, preference_data: MatchingPreferencesModel, user: UserModel):
        self.preference_data = preference_data
        self.user = user

    def create_project_metric(self):
        project_pref = self.preference_data.project_pref
        if project_pref == ProjectPreference.SAME:
            return Metrics.SameProjectMetric(self.user)
        elif project_pref == ProjectPreference.DIFFERENT:
            return Metrics.DifferentProjectMetric(self.user)
        elif project_pref == ProjectPreference.DONT_CARE:
            return Metrics.DontCaraMetric(self.user)

    def create_age_group_metric(self):
        age_group_pref = self.preference_data.age_group_pref
        if age_group_pref == AgeGroupPreference.SAME:
            return Metrics.SameAgeGroupMetric(self.user)
        elif age_group_pref == AgeGroupPreference.HIGHER:
            return Metrics.HigherAgeGroupMetric(self.user)
        elif age_group_pref == AgeGroupPreference.LOWER:
            return Metrics.LowerAgeGroupMetric(self.user)
        elif age_group_pref == AgeGroupPreference.DONT_CARE:
            return Metrics.DontCaraMetric(self.user)
        # TODO: for now, substitute with error handling later
        return Metrics.DontCaraMetric(self.user)

    def create_interests_metric(self):
        interest_pref = self.preference_data.interests_pref
        if interest_pref == InterestsPreferences.SAME:
            return Metrics.SameInterestsMetric(self.user)
        if interest_pref == InterestsPreferences.DIFFERENT:
            return Metrics.DifferentInterestsMetric(self.user)
        return Metrics.DontCaraMetric(self.user)

    """
    Metrics not configurable by the user
    """

    def create_liked_back_metric(self):
        return Metrics.LikedBackMetric(self.user)

    def create_has_matches_metric(self):
        return Metrics.HasMatchesMetric(self.user)

    def create_is_inactive_metric(self):
        return Metrics.IsInactiveMetric(self.user)


class MetaMetricFactory:
    @classmethod
    def create_sum_metric(cls, metric_list):
        return MetaMetrics.SumMetric(metric_list)
