<?php
/**
 * User Roles (extensible levels)
 * PHP User Registration - https://rskworld.in
 * Developer: Molla Samser | RSK World
 * Contact: help@rskworld.in | +91 93305 39277
 * Year: 2026
 */

define('ROLE_USER', 'user');
define('ROLE_MODERATOR', 'moderator');
define('ROLE_ADMIN', 'admin');
define('ROLE_SUPERADMIN', 'superadmin');

// Ordered from lowest to highest (for permission checks)
function getAllRoles(): array {
    return [ROLE_USER, ROLE_MODERATOR, ROLE_ADMIN, ROLE_SUPERADMIN];
}

function getRoleLabel(string $role): string {
    $labels = [
        ROLE_USER       => 'User',
        ROLE_MODERATOR  => 'Moderator',
        ROLE_ADMIN      => 'Admin',
        ROLE_SUPERADMIN => 'Super Admin',
    ];
    return $labels[$role] ?? $role;
}

function canAssignRole(string $assignerRole, string $targetRole): bool {
    $order = array_flip(getAllRoles());
    $assignerLevel = $order[$assignerRole] ?? -1;
    $targetLevel = $order[$targetRole] ?? 0;
    return $assignerLevel >= $targetLevel; // can assign same or lower level only
}
