from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticated

from core.apps.eggs.models import User
from core.apps.eggs.serializers import (
    AddSkladSerializer,
    SkladListSerializer,
)
from core.http.permissions import IsRole


class AddSkladViewSet(viewsets.ModelViewSet):
    permission_classes = [IsAuthenticated, IsRole(["admin"])]
    queryset = User.objects.filter(role="sklad")
    http_method_names = ["get", "post"]

    def get_serializer_class(self):
        if self.request.method == "GET":
            return SkladListSerializer
        else:
            return AddSkladSerializer
