"""
管理员模块权限
"""
from rest_framework.permissions import BasePermission


class IsAdminUser(BasePermission):
    """
    验证是否为管理员用户（来自AdminUser模型）
    """
    def has_permission(self, request, view):
        from apps.admins.models import AdminUser
        return (
            request.user and 
            request.user.is_authenticated and 
            isinstance(request.user, AdminUser) and
            request.user.is_active
        )


class IsSuperAdmin(BasePermission):
    """
    验证是否为超级管理员
    """
    def has_permission(self, request, view):
        from apps.admins.models import AdminUser
        return (
            request.user and 
            request.user.is_authenticated and 
            isinstance(request.user, AdminUser) and
            request.user.role == 'super_admin'
        )


class IsAdminOrOperator(BasePermission):
    """
    验证是否为管理员或操作员
    """
    def has_permission(self, request, view):
        from apps.admins.models import AdminUser
        return (
            request.user and 
            request.user.is_authenticated and 
            isinstance(request.user, AdminUser) and
            request.user.role in ['super_admin', 'admin', 'operator']
        )
