<?php

use api\classes\API_system_modules;

session_start();
require_once "{$_SERVER['DOCUMENT_ROOT']}/api/classes/API_system_modules.php";

$API_system_modules = new API_system_modules();

if ($API_system_modules->request_method === 'GET') {
    $API_system_modules->checkPermissions('admin-modules', 'RO');

    $modules = $API_system_modules->getModules();

    $API_system_modules->apiOutput($code = 200, ['success' => $modules], '');
} elseif ($API_system_modules->request_method === 'PUT') {
    # Enable or disable a module
    $API_system_modules->checkPermissions('admin-modules', 'RW');

    # This api call, when called from the frontend will not be forwarding to a url.
    $API_system_modules->return_url = false;

    $requiredFields = [
        'module_uuid' => ['type' => 'uuid'],
        'module_enabled' => ['type' => 'boolean'],
    ];
    $API_system_modules->validateData($requiredFields);

    $API_system_modules->enableModule();

}

