<?php

namespace api\classes;

use api\classes\API;

require_once 'API.php';

class API_system_modules extends API
{
    public function getModules($returnBoolean = false)
    {
        list($query, $types, $params) = $this->buildDynamicQuery('system_modules');

        $items = $this->generalGetFunction($query, $types, $params, $returnBoolean, 'Modules');

        return $items;
    }

    public function enableModule()
    {

        $module_uuid_enabled = ($this->data['module_enabled']) ? 1 : 0;

        # Module 'system cannot be disabled'
        $query = "UPDATE system_modules SET module_enabled = ? WHERE module_uuid = ? AND module_slugify != 'system'";
        $stmt = $this->prepareStatement($query);
        $stmt->bind_param('is', $module_uuid_enabled, $this->data['module_uuid']);

        if ($this->executeStatement($stmt)) {
            $this->apiOutput(200, ['success' => 'Module ' . ($module_uuid_enabled ? 'enabled' : 'disabled') . ' successfully.']);
        }
    }
}