#!/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::True';

use Cpanel::Plugins::Components::Rules::True ();

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

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

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

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

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

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

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

    subtest 'Named arguments with campaign_id' => sub {
        my $config      = { test => 'value' };
        my $campaign_id = 'test-campaign';
        my $rule        = Cpanel::Plugins::Components::Rules::True->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(), !!1,          "Rule still returns true with campaign_id";
    };
};

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

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

    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::True->new($config);
            is $rule->is_allowed(), !!1, "Returns true regardless of config: " . explain($config);
        }
    };
};

subtest 'Integration with rule system' => sub {
    subtest 'Inheritance from Base class' => sub {
        my $rule = Cpanel::Plugins::Components::Rules::True->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::True->new();
        my $result = $rule->is_allowed();

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

done_testing;

# END AUGMENT GENERATED CODE
