#!/usr/local/cpanel/3rdparty/bin/perl -w
#                                      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.

package t::medium::Cpanel::API::EcosystemFeatures;

use cPstrict;

use Test2::V0;

use Test::Exception;
use Test::MockFile;
use Test::MockObject;

use Test::Cpanel::Policy;

use parent qw(
  Cpanel::TestObj
);

use Cpanel::Result ();
use Cpanel::Args   ();

use Whostmgr::API::1::EcosystemFeatures();

use Whostmgr::API::1::Utils ();

__PACKAGE__->new()->runtests() if !caller;

#----------------------------------------------------------------------

#e.g., num_method_tests()
sub new ( $class, @args ) {
    my $self = $class->SUPER::new(@args);
    return $self;
}

#e.g., set environs before running tests
sub runtests ( $self, @args ) {
    return $self->SUPER::runtests(@args);
}

sub test_local_enable : Tests(3) ($self) {
    my @mocks = $self->mock_subs(
        'Common::Plugins::Setup::run_from_module' => 1,
    );

    my %good_data = (
        'monitoring plugin' => { 'plugin' => 'cpanel-monitoring-plugin' },
    );

    my $expected_metadata = {
        'result' => 1,
        'reason' => 'OK'
    };

    foreach my $case ( keys %good_data ) {
        my $metadata = {};
        Whostmgr::API::1::EcosystemFeatures::local_enable( $good_data{$case}, $metadata );
        is( $metadata, $expected_metadata, "local_enable works as expected for $case." );
    }

    my %bad_data = (
        'bad key' => {
            'bad key' => 'cpanel-monitoring-plugin',
        },
        'no args' => {},
    );

    foreach my $case ( keys %bad_data ) {
        my $metadata = {};
        dies_ok(
            sub {
                Whostmgr::API::1::EcosystemFeatures::local_enable( $bad_data{$case}, $metadata );
            },
            "local_enable dies as expected for $case."
        );
    }

    return;

}

sub test_local_disable : Tests() ($self) {
    my @mocks = $self->mock_subs(
        'Common::Plugins::Setup::run_from_module' => 1,
    );

    my %good_data = (
        'monitoring plugin' => { 'plugin' => 'cpanel-monitoring-plugin' },
    );

    my $expected_metadata = {
        'result' => 1,
        'reason' => 'OK'
    };

    foreach my $case ( keys %good_data ) {
        my $metadata = {};
        Whostmgr::API::1::EcosystemFeatures::local_disable( $good_data{$case}, $metadata );
        is( $metadata, $expected_metadata, "local_disable works as expected for $case." );
    }

    my %bad_data = (
        'bad key' => {
            'bad key' => 'cpanel-monitoring-plugin',
        },
        'no args' => {},
    );

    foreach my $case ( keys %bad_data ) {
        my $metadata = {};
        dies_ok(
            sub {
                Whostmgr::API::1::EcosystemFeatures::local_disable( $bad_data{$case}, $metadata );
            },
            "local_disable dies as expected for $case."
        );
    }

    return;

}

1;
