#!/usr/local/cpanel/3rdparty/bin/perl

#                                      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.

use cPstrict;
use Test::Cpanel::Policy;

use Test2::V0;
use Test2::Tools::Explain;
use Test2::Tools::Compare;
use Test2::Plugin::NoWarnings;

use Test::MockModule;
use Test::MockFile;

BEGIN {
    $INC{'Cpanel/Logger.pm'} = 1;
    package Cpanel::Logger;
    sub new { return bless {}, shift; }
}

my @mock_files = (
    Test::MockFile->dir('/var/log'),
    Test::MockFile->file('/var/log/comet_backup.log'),
);

use Whostmgr::CometBackup::Logger ();

subtest 'Logger - new instance with default log level' => sub {
    my $mock_module = Test::MockModule->new('Whostmgr::CometBackup::Logger');
    $mock_module->redefine( '_ensure_log_directory' => sub { } );
    
    my $logger = Whostmgr::CometBackup::Logger->new();
    
    ok( defined $logger, 'Logger instance created' );
    is( ref $logger, 'Whostmgr::CometBackup::Logger', 'Correct class' );
};

subtest 'Logger - new instance with custom log level' => sub {
    my $mock_module = Test::MockModule->new('Whostmgr::CometBackup::Logger');
    $mock_module->redefine( '_ensure_log_directory' => sub { } );
    
    my $logger = Whostmgr::CometBackup::Logger->new( log_level => 'debug' );
    
    ok( defined $logger, 'Logger instance with custom log_level created' );
};

subtest 'Logger - get_log_level' => sub {
    my $mock_module = Test::MockModule->new('Whostmgr::CometBackup::Logger');
    $mock_module->redefine( '_ensure_log_directory' => sub { } );
    
    my $logger = Whostmgr::CometBackup::Logger->new( log_level => 'info' );
    my $level = $logger->get_log_level();
    
    is( $level, 'info', 'Returns configured log level' );
};

subtest 'Logger - set_log_level' => sub {
    my $mock_module = Test::MockModule->new('Whostmgr::CometBackup::Logger');
    $mock_module->redefine( '_ensure_log_directory' => sub { } );
    
    my $logger = Whostmgr::CometBackup::Logger->new();
    $logger->set_log_level('debug');
    
    is( $logger->get_log_level(), 'debug', 'Log level updated' );
};

subtest 'Logger - info method exists' => sub {
    ok( defined &Whostmgr::CometBackup::Logger::info, 'info method exists' );
};

subtest 'Logger - warn method exists' => sub {
    ok( defined &Whostmgr::CometBackup::Logger::warn, 'warn method exists' );
};

subtest 'Logger - error method exists' => sub {
    ok( defined &Whostmgr::CometBackup::Logger::error, 'error method exists' );
};

subtest 'Logger - debug method exists' => sub {
    ok( defined &Whostmgr::CometBackup::Logger::debug, 'debug method exists' );
};

subtest 'Logger - get_log_level method exists' => sub {
    ok( defined &Whostmgr::CometBackup::Logger::get_log_level, 'get_log_level method exists' );
};

subtest 'Logger - set_log_level method exists' => sub {
    ok( defined &Whostmgr::CometBackup::Logger::set_log_level, 'set_log_level method exists' );
};

done_testing();
