<?php

declare(strict_types=1);

namespace apexl\Io\modules\user\hooks;

use apexl\Io\interfaces\AbstractHook;
use apexl\Io\modules\user\Middleware\SessionMiddleware;
use Exception;

/**
 * Dynamic permissions.
 * We need to loop over all known roles and create an "assign role" permission.
 */
final readonly class RegisterRolePermissions implements AbstractHook
{

    public function hooks(): array
    {
        return [SessionMiddleware::HOOK__POST_AUTH];
    }

    /**
     * @throws Exception
     */
    public function __invoke(int $userId): void
    {
//        if (!System::$installing) {
//            $permissions = Permissions::getInstance();
//
//            $roleEntity = new roleEntity();
//            $roles = $roleEntity->loadMultiple();
//            foreach ($roles as $role) {
//                $permissions->registerPermission(
//                    sprintf('AssignRole_%s', $role->id),
//                    sprintf('Assign Role: %s', $role->name),
//                    'Assign Roles'
//                );
//            }
//        }
    }
}
