from Matching.AbstractGroupMatcher import AbstractGroupMatcher
from Models import GroupMatchingDeclarationModel
from Matching.Metrics import *
from app import db


class ProjectGroupMatcher(AbstractGroupMatcher):

    def __init__(self, project):
        super().__init__(f"Study group for {project.name}")
        self.project = project

    def get_metric(self):
        return SameAgeGroupMetric(None) + SameProjectMetric(None) * 5 + LikedBackMetric(None) * 2

    def query_users(self):
        return GroupMatchingDeclarationModel.query \
            .filter(GroupMatchingDeclarationModel.declared_project == self.project) \
            .first().matchable_users

    def after_successful_matching(self):
        gmdm = GroupMatchingDeclarationModel.query \
            .filter(GroupMatchingDeclarationModel.declared_project == self.project) \
            .first()
        gmdm.matchable_users = []
        db.session.add(gmdm)
        db.session.commit()
