from django.shortcuts import render
from rest_framework import viewsets
from rest_framework import permissions
from api.serializers import ContainerSerializer, ContainerTypeSerializer, AssetSerializer, GtinProductSerializer
from container.models import Container, ContainerType
from asset.models import Asset, GtinProduct


class ContainerViewSet(viewsets.ModelViewSet):
    """
    API endpoint that allows containers to be viewed or edited.
    """
    queryset = Container.objects.all().order_by('named_id')
    serializer_class = ContainerSerializer
    permission_classes = [permissions.IsAuthenticated]
    filterset_fields = ['named_id', 'color']


class ContainerTypeViewSet(viewsets.ModelViewSet):
    """
    API endpoint that allows container-types to be viewed or edited.
    """
    queryset = ContainerType.objects.all()
    serializer_class = ContainerTypeSerializer
    permission_classes = [permissions.IsAuthenticated]
    filterset_fields = ['named_id', 'has_cover', 'contains_container']


class AssetViewSet(viewsets.ModelViewSet):
    """
    API endpoint that allows containers to be viewed or edited.
    """
    queryset = Asset.objects.all().order_by('named_id')
    serializer_class = AssetSerializer
    permission_classes = [permissions.IsAuthenticated]
    filterset_fields = ['named_id', 'quantity']



class GtinProductViewSet(viewsets.ModelViewSet):
    """
    API endpoint that allows containers to be viewed or edited.
    """
    queryset = GtinProduct.objects.all().order_by('gtin')
    serializer_class = GtinProductSerializer
    permission_classes = [permissions.IsAuthenticated]
    filterset_fields = ['gtin']

