import django_filters
from scrobbles.constants import Visibility
from scrobbles.models import Scrobble


class ScrobbleFilter(django_filters.FilterSet):
    media_type = django_filters.ChoiceFilter(choices=Scrobble.MediaType.choices)
    visibility = django_filters.ChoiceFilter(choices=Visibility.choices)
    in_progress = django_filters.BooleanFilter()
    played_to_completion = django_filters.BooleanFilter()
    source = django_filters.CharFilter(lookup_expr="icontains")
    timestamp_after = django_filters.DateTimeFilter(
        field_name="timestamp", lookup_expr="gte"
    )
    timestamp_before = django_filters.DateTimeFilter(
        field_name="timestamp", lookup_expr="lte"
    )

    class Meta:
        model = Scrobble
        fields = [
            "media_type",
            "visibility",
            "in_progress",
            "played_to_completion",
            "source",
            "timestamp_after",
            "timestamp_before",
        ]
