"""Filters for app Product."""
from django.core.validators import EMPTY_VALUES
from django_filters import rest_framework as filters

from product import models


class ProductFilterSet(filters.FilterSet):
    """Product filter set."""

    establishment_id = filters.NumberFilter()
    current_product = filters.CharFilter(method='without_current_product')
    product_type = filters.CharFilter(method='by_product_type')
    product_subtype = filters.CharFilter(method='by_product_subtype')

    class Meta:
        """Meta class."""
        model = models.Product
        fields = [
            'establishment_id',
            'product_type',
            'product_subtype',
        ]

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

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

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