
#                                      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::Template::Plugin::Monitoring;

use cPstrict;

use base 'Template::Plugin';

use Whostmgr::360Monitoring::Setup ();
use Whostmgr::360Monitoring::User  ();
use Cpanel::PwCache                ();

sub get_signin_info ($plugin) {
    my $user_info;

    if ( Whostmgr::360Monitoring::Setup::is_setup() ) {
        $user_info = Whostmgr::360Monitoring::Setup::get_credentials();
    }
    else {
        $user_info = eval { Whostmgr::360Monitoring::Setup::initialize(); };
        if ( my $exception = $@ ) {
            return {
                error => $exception,
            };
        }
    }
    return {
        user_id => $user_info->user_id,
        api_key => $user_info->api_key,
    };
}

sub is_ready {
    return Whostmgr::360Monitoring::Setup::is_taskqueue_clear();
}

sub is_allow {

    # return true if enable-plugin rules are satisfied
    return 1 if Whostmgr::360Monitoring::Setup::is_360Monitoring_allowed();

    return Whostmgr::360Monitoring::Setup::is_360Monitoring_setup_previously();

}

1;
