"""
Platform Permissions
Custom permission classes for platform-level operations
"""
from rest_framework import permissions
from smoothschedule.identity.users.models import User


class IsPlatformAdmin(permissions.BasePermission):
    """
    Permission class that only allows platform admins (superuser, platform_manager)
    """
    message = "Platform admin access required."

    def has_permission(self, request, view):
        if not request.user or not request.user.is_authenticated:
            return False

        # Allow superusers and platform managers
        return request.user.role in [
            User.Role.SUPERUSER,
            User.Role.PLATFORM_MANAGER
        ]


class IsPlatformUser(permissions.BasePermission):
    """
    Permission class that allows any platform-level user
    (superuser, platform_manager, platform_support, platform_sales)
    """
    message = "Platform user access required."

    def has_permission(self, request, view):
        if not request.user or not request.user.is_authenticated:
            return False

        # Allow any platform-level role
        return request.user.role in [
            User.Role.SUPERUSER,
            User.Role.PLATFORM_MANAGER,
            User.Role.PLATFORM_SUPPORT,
            User.Role.PLATFORM_SALES,
        ]
