<?php

namespace routes;

use classes\authentication;
use classes\response;
use classes\router;
use objects\logs_o;
use traits\route_t;

class moduleEntraRoute
{
    use route_t;

    public function run(): void
    {
        global /** @var response $response */
        /** @var router $router */
        $router, $response;


        /** Modules > Entra > Users > GET */
        $this->get('/modules/entra/users', function () {
            global $response;
            self::requirePermission('modules_entra_users');
            $user = (new authentication())->get_user();
            if ($user) {
                $result = (new \classes\entra())->get_users();
                $response->success($result);
            } else {
                (new logs_o())->add('modules_entra_users', 'global', 1, 0, 'MODULES_ENTRA_users', 'User attempted to access Entra users without being logged in');
                $response->error('Invalid session', 400);
            }
        },
            [
                'modules_entra_users' => 'List entra users',
            ]
        );
    }
}