"""نقش‌های استاندارد پلتفرم (هماهنگ با Keycloak realm)."""
from __future__ import annotations

import enum

from shared.security import CurrentUser


class PlatformRole(str, enum.Enum):
    PLATFORM_ADMIN = "platform_admin"
    TENANT_ADMIN = "tenant_admin"
    TENANT_MEMBER = "tenant_member"
    PENDING_TENANT_ADMIN = "pending_tenant_admin"
    USER = "user"
    SERVICE_ACCOUNT = "service_account"


def has_role(user: CurrentUser, role: str | PlatformRole) -> bool:
    role_value = role.value if isinstance(role, PlatformRole) else role
    return role_value in user.roles


def has_any_role(user: CurrentUser, *roles: str | PlatformRole) -> bool:
    return any(has_role(user, r) for r in roles)
