"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: ksp-servicestelle@sgdnord.rlp.de
Created on: 18.08.22

"""
from django import forms
from django.db.models import QuerySet
from django.utils.translation import gettext_lazy as _
import django_filters


class RecordableTableFilterMixin(django_filters.FilterSet):
    """ A mixin for AbstractTableFilter

    Specialized on filtering recordable model types

    """
    sr = django_filters.BooleanFilter(
        method='filter_show_recorded',
        label=_("Show recorded"),
        label_suffix=_(""),
        widget=forms.CheckboxInput(
            attrs={
                "class": "form-check-input",
                "title": _("If activated also shows entries which have been already recorded"),
            }
        )
    )

    class Meta:
        abstract = True

    def filter_show_recorded(self, queryset, name, value) -> QuerySet:
        """ Filters queryset depending on value of 'show_recorded' setting

        Args:
            queryset ():
            name ():
            value ():

        Returns:

        """
        if not value:
            return queryset.filter(
                recorded=None,
            )
        else:
            return queryset

