from django.contrib.contenttypes.models import ContentType
from django.utils.translation import gettext as _
from wbcore import filters

from wbfdm.contrib.metric.models import InstrumentMetric

from .registry import backend_registry


class InstrumentMetricFilterSet(filters.FilterSet):
    key = filters.ChoiceFilter(choices=backend_registry.get_choices(), label="Key")
    basket_content_type = filters.ModelChoiceFilter(
        queryset=ContentType.objects.all(),
        endpoint="wbcore:contenttyperepresentation-list",
        value_key="id",
        label_key="{{app_label}} | {{model}}",
        label=_("Basket Content Type"),
    )

    class Meta:
        model = InstrumentMetric
        fields = {
            "basket_content_type": ["exact"],
            "basket_id": ["exact"],
            "instrument": ["exact"],
            "key": ["exact"],
            "date": ["lte", "gte", "exact"],
            "parent_metric": ["exact", "isnull"],
        }
