# api/permissions.py
"""
Custom permission classes for the API.
"""

from rest_framework.permissions import BasePermission

# api/permissions.py - update IsTeacher for case-insensitivity if needed, but with lowercase now it's fine
class IsTeacher(BasePermission):
    def has_permission(self, request, view):
        return (
            request.user
            and request.user.is_authenticated
            and request.user.role.lower() == 'teacher'
        )
    def has_object_permission(self, request, view, obj):
        # If you need object-level checks (e.g., teacher owns the class), implement here.
        # For now, fallback to general permission.
        return self.has_permission(request, view)

class IsAdmin(BasePermission):
    """
    Allows access only to authenticated admins or super admins.
    """
    def has_permission(self, request, view):
        return (
            request.user
            and request.user.is_authenticated
            and request.user.role in ['admin', 'super_admin']
        )