package Whostmgr::API::1::EcosystemFeatures;

=encoding utf8

=head1 NAME

Whostmgr::API::1::EcosystemFeatures

=head1 DESCRIPTION

This module contains whmapi methods related to Plugins..

=head1 FUNCTIONS

=cut

use cPstrict;
use Cpanel::Exception       ();
use Whostmgr::API::1::Utils ();
use Common::Plugins::Setup  ();

use constant NEEDS_ROLE => {
    local_enable  => undef,
    local_disable => undef,
};

my $logger;

=head2 local_enable()

This function allows a local administrator to enable a plugin. The
checks it bypasses are dependent on the plugin's local_enable call.

=head3 ARGUMENTS

=over

=item plugin - string Required. The plugin name in all lowercase,
separated by dashes. For example:

cpanel-monitoring-plugin

=back

=cut

sub local_enable {
    my ( $args, $metadata ) = @_;

    my $plugin_name = Whostmgr::API::1::Utils::get_required_argument( $args, 'plugin' );

    Common::Plugins::Setup::run_from_module( 'Whostmgr', $plugin_name, 'enable' );

    Whostmgr::API::1::Utils::set_metadata_ok($metadata);

    return;
}

=head2 local_disable()

This function allows a local administrator to disable a plugin for
the server, instead of it being forced-on from Webpros.

After local_disable() has been used, local_enable() must be used to
re-enable it.

=head3 ARGUMENTS

=over

=item plugin - string Required. The plugin name in all lowercase,
separated by dashes. For example:

cpanel-monitoring-plugin

=back

=cut

sub local_disable {
    my ( $args, $metadata ) = @_;

    my $plugin_name = Whostmgr::API::1::Utils::get_required_argument( $args, 'plugin' );

    Common::Plugins::Setup::run_from_module( 'Whostmgr', $plugin_name, 'disable' );

    Whostmgr::API::1::Utils::set_metadata_ok($metadata);

    return;
}

sub APPLIST {
    return {
        local_enable => [
            namespace => 'EcosystemFeatures',
            method    => 'local_enable',
            argsmode  => 'strict',
        ],
        local_disable => [
            namespace => 'EcosystemFeatures',
            method    => 'local_disable',
            argsmode  => 'strict',
        ],
    };
}

1;
