public function create_category(string $name = null) : int {
        global $DB;
        $params = ['component' => $this->get_component(), 'area' => $this->get_area(), 'itemid' => $this->get_itemid()];

        if (empty($name)) {
            for ($suffix = 0; $suffix < 100; $suffix++) {
                $name = $this->generate_category_name($suffix);
                if (!$DB->record_exists(category::TABLE, $params + ['name' => $name])) {
                    break;
                }
            }
        }

        $category = category_controller::create(0, (object)['name' => $name], $this);
        api::save_category($category);
        $this->clear_configuration_cache();
        return $category->get('id');
    }