# coding=utf-8

from rest_framework import generics
from utils.permission import IsCustomerUser

from utils import response_ok

from apps.store.filters import ShopFilter

from .serializers import *


class ShopViewSet(generics.ListAPIView):
    # permission_classes = [IsCustomerUser, ]
    queryset = Shop.objects.filter(delete=False)
    serializer_class = ShopSerializer

    def filter_queryset(self, queryset):
        f = ShopFilter(self.request.GET, queryset=queryset)
        return f.qs

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        serializer = self.get_serializer(queryset, many=True)
        return response_ok(serializer.data)


class ShopMapListView(generics.ListAPIView):
    # permission_classes = [IsCustomerUser, ]
    queryset = Shop.objects.filter(delete=False)
    serializer_class = ShopDetailSerializer

    def filter_queryset(self, queryset):
        f = ShopFilter(self.request.GET, queryset=queryset)
        return f.qs

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        serializer = self.get_serializer(queryset, many=True)
        return response_ok(serializer.data)
