"""This module holds the managers and querysets for the ``evaluations`` app"""

from django.db import models

from mtp.apps.sync.managers import SyncableQuerySet


class ExerciseManager(models.Manager):
    """Manager used by the ``Exercise`` model."""

    pass


class ExerciseQueryset(SyncableQuerySet, models.QuerySet):
    """QuerySet used by the ``Exercise`` model."""

    def for_evaluation(self, evaluation):
        """
        Filter only ``Exercise`` instances related to the given ``Evaluation``.

        Returns
        -------
        Queryset of ``mtp.apps.evaluations.models.Evaluation``

        """
        return self.filter(evaluation=evaluation)

    def for_user(self, user):
        """
        Filter only ``Exercise`` instances linked to a ``Training`` instance
        owned by the given user.

        Returns
        -------
        Queryset of ``mtp.apps.evaluations.models.Exercise``

        """

        return self.filter(evaluation__training__owner=user)


class CriterionManager(models.Manager):
    """Manager used by the ``Criterion`` model."""

    pass


class CriterionQueryset(SyncableQuerySet, models.QuerySet):
    """QuerySet used by the ``Criterion`` model."""

    def for_exercise(self, exercise):
        """
        Filter only ``Criterion`` objects related to the given ``Exercise``.

        Returns
        -------
        Queryset of ``mtp.apps.trainings.models.Criterion`` objects.

        """
        return self.filter(exercise=exercise)

    def qualitative(self):
        """
        Filter only qualitative ``Criterion`` objects.

        Returns
        -------
        Queryset of ``mtp.apps.evaluations.models.Criterion`` objects.

        """
        from .models import Criterion
        return self.filter(criterion_type=Criterion.CRITERION_TYPES.QUALITATIVE)

    def quantitative(self):
        """
        Filter only quantitative ``Criterion`` objects.

        Returns
        -------
        Queryset of ``mtp.apps.evaluations.models.Criterion`` objects.

        """
        from .models import Criterion
        return self.filter(criterion_type=Criterion.CRITERION_TYPES.QUANTITATIVE)


class RatingManager(models.Manager):
    """Manager used by the ``Rating`` model."""

    pass


class RatingQueryset(SyncableQuerySet, models.QuerySet):
    """QuerySet used by the ``Rating`` model."""

    pass
