#!/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

# BEGIN AUGMENT GENERATED CODE
use cPstrict;

use Test2::V0;
use Test2::Tools::Explain;
use Test2::Plugin::NoWarnings;
use Test2::Tools::Subtest;
use Test2::Tools::Exception;

use Test::Cpanel::Policy testing => 'Cpanel::Plugins::Components::Rules::False';

use Cpanel::Plugins::Components::Rules::False;

subtest 'Basic functionality' => sub {
    subtest 'False rule always returns false with no config' => sub {
        my $rule = Cpanel::Plugins::Components::Rules::False->new();
        my $got  = $rule->is_allowed();
        is $got, !!0, "False rule returns false with no configuration";
    };

    subtest 'False rule always returns false with scalar config' => sub {
        my $rule = Cpanel::Plugins::Components::Rules::False->new(1);
        my $got  = $rule->is_allowed();
        is $got, !!0, "False rule returns false with scalar configuration";
    };

    subtest 'False rule always returns false with hash config' => sub {
        my $rule = Cpanel::Plugins::Components::Rules::False->new( { some => 'value' } );
        my $got  = $rule->is_allowed();
        is $got, !!0, "False rule returns false with hash configuration";
    };

    subtest 'False rule always returns false with array config' => sub {
        my $rule = Cpanel::Plugins::Components::Rules::False->new( [ 'some', 'values' ] );
        my $got  = $rule->is_allowed();
        is $got, !!0, "False rule returns false with array configuration";
    };
};

subtest 'Constructor argument handling' => sub {
    subtest 'Single scalar argument' => sub {
        my $rule = Cpanel::Plugins::Components::Rules::False->new(42);
        is $rule->config,       1,  "Single scalar argument stored as config";
        is $rule->is_allowed(), !!0, "Rule still returns false";
    };

    subtest 'Single hash reference argument' => sub {
        my $config = { test => 'value' };
        my $rule   = Cpanel::Plugins::Components::Rules::False->new($config);
        is $rule->config,       $config, "Single hash reference stored as config";
        is $rule->is_allowed(), !!0,     "Rule still returns false";
    };

    subtest 'Named arguments' => sub {
        my $config = { test => 'value' };
        my $rule   = Cpanel::Plugins::Components::Rules::False->new( config => $config );
        is $rule->config,       $config, "Named config argument stored correctly";
        is $rule->is_allowed(), !!0,     "Rule still returns false";
    };

    subtest 'Named arguments with campaign_id' => sub {
        my $config      = { test => 'value' };
        my $campaign_id = 'test-campaign';
        my $rule        = Cpanel::Plugins::Components::Rules::False->new(
            config      => $config,
            campaign_id => $campaign_id
        );
        is $rule->config,       $config,      "Named config argument stored correctly";
        is $rule->campaign_id,  $campaign_id, "Campaign ID stored correctly";
        is $rule->is_allowed(), !!0,          "Rule still returns false with campaign_id";
    };
};

subtest 'Edge cases and consistency' => sub {
    subtest 'Multiple calls return consistent results' => sub {
        my $rule = Cpanel::Plugins::Components::Rules::False->new();
        my @results;
        for my $i ( 1 .. 10 ) {
            push @results, $rule->is_allowed();
        }
        is \@results, [ ( !!0 ) x 10 ], "Multiple calls consistently return false";
    };

    subtest 'Different instances return same result' => sub {
        my @rules   = map { Cpanel::Plugins::Components::Rules::False->new() } ( 1 .. 5 );
        my @results = map { $_->is_allowed() } @rules;
        is \@results, [ ( !!0 ) x 5 ], "Different instances consistently return false";
    };

    subtest 'Ignores configuration content completely' => sub {
        my @configs = (
            undef,
            0,
            1,
            '',
            'false',
            'true',
            [],
            {},
            { complex => { nested => { structure => 'ignored' } } },
            [ 'complex', 'array', 'ignored' ]
        );

        for my $config (@configs) {
            my $rule = Cpanel::Plugins::Components::Rules::False->new($config);
            is $rule->is_allowed(), !!0, "Returns false regardless of config: " . explain($config);
        }
    };
};

subtest 'Integration with rule system' => sub {
    subtest 'Inheritance from Base class' => sub {
        my $rule = Cpanel::Plugins::Components::Rules::False->new();
        isa_ok $rule, 'Cpanel::Plugins::Components::Rules::Base';
        can_ok $rule, 'is_allowed';
        can_ok $rule, 'config';
        can_ok $rule, 'normalize';
    };

    subtest 'Boolean return type verification' => sub {
        my $rule   = Cpanel::Plugins::Components::Rules::False->new();
        my $result = $rule->is_allowed();

        # Verify it's a proper boolean false
        ok !$result, "Result is falsy";
        is $result,      !!0, "Result equals !!0";
        is ref($result), '',  "Result is not a reference";
    };
};

done_testing;

# END AUGMENT GENERATED CODE
