
#                                      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 Cpanel::Config::ConfigObj::Driver::ServerMonitoring::META;

use cPstrict;

=encoding utf-8

=head1 NAME

Cpanel::Config::ConfigObj::Driver::ServerMonitoring::META

=head1 DESCRIPTION

Feature Showcase metadata for ServerMonitoring

=cut

use parent qw(Cpanel::Config::ConfigObj::Interface::Config::Version::v1);

use Try::Tiny;

use Cpanel::LoadModule ();

our $VERSION = '1.0';

=head2 translate

Returns the string. Provides the string to the locale tool.

=cut

sub translate ($string) { return $string; }

my $short = translate("Server Monitoring");

sub meta_version {
    return 1;
}

=head2 get_driver_name()

Returns the driver name. This name is used as the filename for the touchfile
put in the C</var/cpanel/activate/features/> directory.

=cut

# Avoids having to deal with locale information
# when all we care about is the driver name.
sub get_driver_name {
    return 'server_monitoring';
}

sub content {
    my ($locale_handle) = @_;

    my $content = {
        'vendor' => 'cPanel, L.L.C.',
        'url'    => 'https://go.cpanel.net/server-monitoring',
        'name'   => {
            'short'  => $short,
            'driver' => get_driver_name(),
        },
        'since'        => '',
        'version'      => $VERSION,
        'readonly'     => 0,
        'defaultvalue' => "Enable",
        'driver'       => get_driver_name(),
    };

    if ($locale_handle) {
        $content->{'abstract'} = $locale_handle->maketext("[asis,cPanel amp() WHM] now provides the [asis,Server Monitoring] feature. You can use [asis,Server Monitoring] to track your server’s performance and up-time statistics.");
    }
    else {
        $content->{'abstract'} = "cPanel & WHM now provides the Server Monitoring feature. You can use Server Monitoring to track your server's performance and up-time statistics.";
    }

    $content->{'name'}->{'long'} = $content->{'name'}->{'short'};

    return $content;
}

sub showcase {
    return 0 unless _validate_rules();
    return { 'is_recommended' => 1, 'is_spotlight_feature' => 0 };
}

sub _validate_rules {
    require Whostmgr::360Monitoring::Config;
    require Cpanel::Plugins::Components::Rules;

    # using mini-app rule validation instead of enable-plugin
    # as enable-plugin looks for feature-flags check and local.disable
    # check will not display the feature_showcase
    my $config     = Whostmgr::360Monitoring::Config::load();
    my $is_allowed = Cpanel::Plugins::Components::Rules->new( 'config' => $config->{'auto-enable-miniapp'} )->is_allowed();
    return $is_allowed;
}

sub acl_desc {
    my ($locale_handle) = @_;
    my %acl_desc = (
        'acl'           => '360_monitoring_acl',
        'default_value' => 1,
        'is_plugin'     => 1,
        'name'          => 'Server Monitoring',    # no need for locale since it'd be asis
    );

    if ($locale_handle) {
        $acl_desc{'acl_subcat'} = locale()->maketext('Monitoring');
    }
    else {
        $acl_desc{'acl_subcat'} = 'Monitoring';
    }
    return \%acl_desc;
}

1;
