#!/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',
    'Cpanel::Plugins::Components::Rules::False',
    'Cpanel::Plugins::Components::Rules'
];

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

subtest 'Integration with Rules system' => sub {
    subtest 'True rule via Rules processor' => sub {
        my $rules  = Cpanel::Plugins::Components::Rules->new( config => { true => 1 } );
        my $result = $rules->is_allowed();
        is $result, !!1, "True rule returns true via Rules processor";
    };

    subtest 'False rule via Rules processor' => sub {
        my $rules  = Cpanel::Plugins::Components::Rules->new( config => { false => 1 } );
        my $result = $rules->is_allowed();
        is $result, !!0, "False rule returns false via Rules processor";
    };

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

    subtest 'False rule with array syntax' => sub {
        my $rules  = Cpanel::Plugins::Components::Rules->new( config => [ false => 1 ] );
        my $result = $rules->is_allowed();
        is $result, !!0, "False rule returns false with array syntax";
    };
};

subtest 'Integration with logical operators' => sub {
    subtest 'AND with True rules' => sub {
        my $rules = Cpanel::Plugins::Components::Rules->new(
            config => [
                and => [
                    { true => 1 },
                    { true => 1 }
                ]
            ]
        );
        my $result = $rules->is_allowed();
        is $result, !!1, "AND of two True rules returns true";
    };

    subtest 'AND with True and False' => sub {
        my $rules = Cpanel::Plugins::Components::Rules->new(
            config => [
                and => [
                    { true  => 1 },
                    { false => 1 }
                ]
            ]
        );
        my $result = $rules->is_allowed();
        is $result, !!0, "AND of True and False returns false";
    };

    subtest 'OR with False rules' => sub {
        my $rules = Cpanel::Plugins::Components::Rules->new(
            config => [
                or => [
                    { false => 1 },
                    { false => 1 }
                ]
            ]
        );
        my $result = $rules->is_allowed();
        is $result, !!0, "OR of two False rules returns false";
    };

    subtest 'OR with True and False' => sub {
        my $rules = Cpanel::Plugins::Components::Rules->new(
            config => [
                or => [
                    { true  => 1 },
                    { false => 1 }
                ]
            ]
        );
        my $result = $rules->is_allowed();
        is $result, !!1, "OR of True and False returns true";
    };

    subtest 'NOT with True rule' => sub {
        my $rules  = Cpanel::Plugins::Components::Rules->new( config => [ not => { true => 1 } ] );
        my $result = $rules->is_allowed();
        is $result, !!0, "NOT of True rule returns false";
    };

    subtest 'NOT with False rule' => sub {
        my $rules  = Cpanel::Plugins::Components::Rules->new( config => [ not => { false => 1 } ] );
        my $result = $rules->is_allowed();
        is $result, !!1, "NOT of False rule returns true";
    };
};

subtest 'Complex rule combinations' => sub {
    subtest 'Nested logical operations' => sub {
        my $rules = Cpanel::Plugins::Components::Rules->new(
            config => [
                and => [
                    [
                        or => [
                            { true  => 1 },
                            { false => 1 }
                        ]
                    ],
                    [ not => { false => 1 } ]
                ]
            ]
        );
        my $result = $rules->is_allowed();
        is $result, !!1, "Complex nested rule (true OR false) AND (NOT false) returns true";
    };

    subtest 'Multiple True/False combinations' => sub {
        my $rules = Cpanel::Plugins::Components::Rules->new(
            config => [
                or => [
                    [
                        and => [
                            { false => 1 },
                            { true  => 1 }
                        ]
                    ],
                    [
                        and => [
                            { true => 1 },
                            { true => 1 }
                        ]
                    ]
                ]
            ]
        );
        my $result = $rules->is_allowed();
        is $result, !!1, "Complex rule (false AND true) OR (true AND true) returns true";
    };
};

done_testing;

# END AUGMENT GENERATED CODE
