/*
 *                                      Copyright 2025 WebPros International, LLC
 *                                                           All rights reserved.
 * copyright@cpanel.net                                         http://cpanel.net
 * This code is subject to the cPanel license. Unauthorized copying is prohibited.
 */

import { WHMAPI } from "@classes/WHMAPI";

/**
 * This class facilitates use of WHMAPI1::EcosystemFeatures
 *
 * @example
 * ```typescript
 * const common = new CommonWhmapi()
 * ``
 */
export class CommonWhmapi extends WHMAPI {
    /**
     * [DUCKS-21]
     * Enable the specified plugin locally on the server
     * @param plugin - name of the plugin to enable
     */
    async enableLocally(plugin: string): Promise<void> {
        const response = await this.call("EcosystemFeatures/local_enable", {
            plugin: plugin,
        });

        if (!response.isSuccess) {
            throw new Error(`Failed to enable ${plugin} \n ${response.error}`);
        }
    }

    /**
     * [DUCKS-21]
     * Disable the specified plugin locally on the server
     * @param plugin - name of the plugin to enable
     */
    async disableLocally(plugin: string): Promise<void> {
        const response = await this.call("EcosystemFeatures/local_disable", {
            plugin: plugin,
        });

        if (!response.isSuccess) {
            throw new Error(`Failed to enable ${plugin} \n ${response.error}`);
        }
    }
}
