"""
Courier History view
"""

from rest_framework import viewsets

from core.apps.eggs import models
from core.apps.eggs import serializers
from core.http.permissions import IsRole


class CourierHistoryViewSet(viewsets.ModelViewSet):
    serializer_class = serializers.CourierHistorySerializer
    http_method_names = ["get"]
    permission_classes = [IsRole(["admin", "courier"])]

    def get_queryset(self):
        """
        This view should return a list of all the courier history
        for the currently authenticated user.
        """
        user = self.request.user
        if user.role == "courier":
            return models.CourierHistory.objects.filter(courier_id=user.id)
        return models.CourierHistory.objects.all()
