"""Account app filters."""
from django.core.validators import EMPTY_VALUES
from django_filters import rest_framework as filters

from account import models


class AccountBackOfficeFilter(filters.FilterSet):
    """Account filter set."""

    role = filters.MultipleChoiceFilter(choices=models.Role.ROLE_CHOICES,
                                        method='filter_by_roles')

    class Meta:
        """Meta class."""

        model = models.User
        fields = (
            'role',
            'email_confirmed',
            'is_staff',
            'is_active',
            'is_superuser',
        )

    def filter_by_roles(self, queryset, name, value):
        if value not in EMPTY_VALUES:
            return queryset.by_roles(value)
        return queryset
