from rest_framework import permissions


class ExamplePermissions:
    class CanAccessView(permissions.BasePermission):
        def has_object_permission(self, request, view, obj):

            return False

        def has_permission(self, request, view):

            return True


class GeneralPermissions:
    class IsService(permissions.BasePermission):
        """if request is made from a service as a service

        Args:
            permissions (_type_): _description_
        """

        def has_object_permission(self, request, view, obj):

            return False

        def has_permission(self, request, view):
            return getattr(request.user, "is_service", False)

    class IsApiKey(permissions.BasePermission):
        """if request is made with an apikey

        Args:
            permissions (_type_): _description_
        """

        def has_permission(self, request, view):
            api_key = str(
                request.META.get("HTTP_API_KEY", "") or request.GET.get("api-key", "")
            )
            return bool(api_key)
