from django_filters.rest_framework import DjangoFilterBackend, filters
from rest_framework import generics, permissions

from partner.models import Partner
from partner.serializers import back as serializers
from utils.permissions import IsEstablishmentManager


class PartnerLstView(generics.ListCreateAPIView):
    """Partner list create view."""
    queryset = Partner.objects.all()
    serializer_class = serializers.BackPartnerSerializer
    pagination_class = None
    permission_classes = [permissions.IsAdminUser | IsEstablishmentManager]
    filter_backends = (DjangoFilterBackend,)
    filterset_fields = (
        'establishment',
        'type',
    )


class PartnerRUDView(generics.RetrieveUpdateDestroyAPIView):
    """Partner RUD view."""
    queryset = Partner.objects.all()
    serializer_class = serializers.BackPartnerSerializer
    permission_classes = [permissions.IsAdminUser | IsEstablishmentManager]
    lookup_field = 'id'
