""" This module holds the managers and querysets for the ``likes`` app. """

from django.db import models

from mtp.apps.sync.managers import SyncableQuerySet


class LikeManager(models.Manager):
    """ The Manager for the ``mtp.apps.likes.models.Like`` model. """

    pass


class LikeQuerySet(SyncableQuerySet, models.QuerySet):
    """ The QuerySet for the ``mtp.apps.likes.models.Like`` model. """

    def for_author(self, author):
        """ Filter only ``Like`` instances that belong to the given author.

        Parameters
        ----------
        author : django ``MTPUser``
            The user which like an object.

        Returns
        -------
        QuerySet of ``mtp.apps.likes.models.Like``
        """
        return self.filter(author=author)

    def for_weight(self, weight):
        """ Filter only ``Like`` instances that belong to the given weight.

        Parameters
        ----------
        weight : int
            The likes weight.

        Returns
        -------
        QuerySet of ``mtp.apps.likes.models.Like``
        """
        return self.filter(weight=weight)

    def for_positive_like(self):
        """ Filter only ``Like`` instances that correspond to a positive like.

        Returns
        -------
        QuerySet of ``mtp.apps.likes.models.Like``
        """
        return self.filter(weight__gt=0)

    def for_negative_like(self):
        """ Filter only ``Like`` instances that correspond to a negative like.

        Returns
        -------
        QuerySet of ``mtp.apps.likes.models.Like``
        """
        return self.filter(weight__lt=0)
