from Core.Dexter.Infrastructure.Domain.FuzzyEngine.FuzzySets.FuzzyMembershipFunction import LinearMembershipFunction, \
    TrapezeMembershipFunction, StepMembershipFunction
from Core.Dexter.Infrastructure.Domain.FuzzyEngine.FuzzySets.FuzzySets import Fuzzyfier, LinguisticVariable
from FacebookDexter.Engine.Algorithms.FuzzyRuleBasedOptimization.Metrics.FacebookAvailableMetricEnum import \
    FacebookAvailableMetricEnum
from FacebookDexter.Infrastructure.Domain.FuzzyEngine.FacebookFuzzySets import FacebookLinguisticVariableEnum

LOW_LINEAR_PARAMS = {
    "a": -10.0 / 3.0,
    "b": 1
}

MEDIUM_LINEAR_PARAMS = {
    "x1": 0.4,
    "a1": 20.0 / 3.0,
    "b1": -5.0 / 3.0,
    "x2": 0.6,
    "a2": -20.0 / 3.0,
    "b2": 5
}

HIGH_LINEAR_PARAMS = {
    "a": 10.0 / 3.0,
    "b": -7.0 / 3.0
}

AGGREGATED_METRIC_FUZZYFIER_COLLECTION = [
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.CPC.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.CPM.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.CTR.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.COST_PER_RESULT.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.COST_PER_APP_INSTALL.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.COST_PER_PURCHASE.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.COST_PER_THRUPLAY.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.FREQUENCY.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW, StepMembershipFunction(a=0, b=3)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     StepMembershipFunction(a=3, b=7)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     StepMembershipFunction(a=7, b=10))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.CR.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.ENGAGEMENT_RATE.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.ROAS.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.RESULTS.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.SPEND.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.REACH.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.LINK_CLICKS.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.PAGE_LIKES.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.IMPRESSIONS.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.PURCHASES.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.VIDEO_PLAYS.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.LEADS.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.RSVPS.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.APP_INSTALLS.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.CONVERSIONS.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.THRUPLAYS.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.UNIQUE_CLICKS.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.POST_LIKES.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.POST_COMMENTS.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.POST_SHARES.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.POST_VIEWS.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.PURCHASES_VALUE.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))]),
    Fuzzyfier(metric_name=FacebookAvailableMetricEnum.CLICKS.value.name,
              linguistic_levels=[
                  LinguisticVariable(FacebookLinguisticVariableEnum.LOW,
                                     LinearMembershipFunction(**LOW_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.MEDIUM,
                                     TrapezeMembershipFunction(**MEDIUM_LINEAR_PARAMS)),
                  LinguisticVariable(FacebookLinguisticVariableEnum.HIGH,
                                     LinearMembershipFunction(**HIGH_LINEAR_PARAMS))])
]
