from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticated

from core.apps.eggs.models import User
from core.apps.eggs.serializers.add_courier import (
    AddCourierSerializer,
    CouriersListSerializer,
)
from core.http.permissions import IsRole


class AddCourierViewSet(viewsets.ModelViewSet):
    permission_classes = [IsAuthenticated, IsRole(["admin"])]
    queryset = User.objects.filter(role="courier")

    def get_serializer_class(self):
        if self.request.method == "GET":
            return CouriersListSerializer
        else:
            return AddCourierSerializer
