<?php

namespace App\Services\Roles;

use App\Models\UserRole;

class RoleSwitchService
{
    public function __construct(private RoleDashboardService $dashboardService)
    {
    }

    public function getUserRoleNames(int $userId): array
    {
        $roles = UserRole::getRolesByUserId($userId);
        return array_values(array_filter(array_map(fn ($r) => (string) ($r['role_name'] ?? ''), $roles)));
    }

    public function switchRole(string $role): string
    {
        return $this->dashboardService->bestDashboardRouteFor([$role]);
    }
}
