from django.conf import settings
from django.db.models import Q
from django.utils.translation import gettext_lazy as _

from rest_framework.views import APIView
from rest_framework import viewsets
from rest_framework.permissions import AllowAny
from rest_framework import response
from rest_framework_extensions.mixins import DetailSerializerMixin

from geotrek.api.mobile.serializers import common as api_serializers
from geotrek.flatpages.models import FlatPage
from geotrek.trekking.models import DifficultyLevel, Practice, Accessibility, Route, Theme, TrekNetwork, POIType, Trek
from geotrek.tourism.models import (InformationDesk, InformationDeskType, TouristicContentType, TouristicEventType,
                                    TouristicContentCategory)
from geotrek.zoning.models import City, District


class SettingsView(APIView):
    permission_classes = [AllowAny, ]

    def get(self, request, *args, **kwargs):
        filters = []
        for filter in settings.ENABLED_MOBILE_FILTERS:
            if filter == 'difficulty' and DifficultyLevel.objects.exists():
                filters.append({
                    "id": "difficulty",
                    "type": "contains",
                    "showAllLabel": _("Show all difficulties"),
                    "hideAllLabel": _("Hide all difficulties")
                })
            if filter == 'lengths':
                filters.append({
                    "id": "lengths",
                    "type": "interval",
                    "showAllLabel": _("Show all lengths"),
                    "hideAllLabel": _("Hide all lengths")
                })
            if filter == 'ascent':
                filters.append({
                    "id": "ascent",
                    "type": "interval",
                    "showAllLabel": _("Show all ascents"),
                    "hideAllLabel": _("Hide all ascents")
                })
            if filter == 'districts' and District.objects.filter(published=True).exists():
                filters.append({
                    "id": "districts",
                    "type": "contains",
                    "showAllLabel": _("Show all districts"),
                    "hideAllLabel": _("Hide all districts")
                })
            if filter == 'cities' and City.objects.filter(published=True).exists():
                filters.append({
                    "id": "cities",
                    "type": "contains",
                    "showAllLabel": _("Show all cities"),
                    "hideAllLabel": _("Hide all cities")
                })
            if filter == 'accessibilities' and Accessibility.objects.exists():
                filters.append({
                    "id": "accessibilities",
                    "type": "contains",
                    "showAllLabel": _("Show all accessibilities"),
                    "hideAllLabel": _("Hide all accessibilities")
                })
            if filter == 'practice' and Practice.objects.exists():
                filters.append({
                    "id": "practice",
                    "type": "contains",
                    "showAllLabel": _("Show all practices"),
                    "hideAllLabel": _("Hide all practices")
                })
            if filter == 'duration':
                filters.append({
                    "id": "duration",
                    "type": "interval",
                    "showAllLabel": _("Show all durations"),
                    "hideAllLabel": _("Hide all durations")
                })
            if filter == 'themes' and Theme.objects.exists():
                filters.append({
                    "id": "themes",
                    "type": "contains",
                    "showAllLabel": _("Show all themes"),
                    "hideAllLabel": _("Hide all themes")