#                                     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
package Cpanel::Plugins::Components::Rules::True;
use cPstrict;

use Moo;
extends 'Cpanel::Plugins::Components::Rules::Base';

=head1 MODULE

C<Cpanel::Plugins::Components::Rules::True>

=head1 DESCRIPTION

A rule that always evaluates to true. This rule is useful for testing purposes,
default allow conditions, or as a placeholder in rule configurations where
unconditional access should be granted.

This class is used when a rule includes a 'true' entry in the configuration.

=head1 SYNOPSIS

Always allow access regardless of any conditions:

  use Cpanel::Plugins::Components::Rules::True;
  my $return = Cpanel::Plugins::Components::Rules::True->new()->is_allowed();
  # $return will always be 1 (true)

When using the declarative JSON syntax:

  {
    "true": 1
  }

Or in array format:

  [
    "true", 1
  ]

The True rule ignores any configuration parameters and always returns true.
This makes it useful for:
- Testing rule evaluation systems
- Providing default allow behavior
- Temporarily bypassing other rule conditions during development
- Creating fallback conditions in complex rule hierarchies

=cut

=head1 METHODS

=over

=item * is_allowed -- Always returns true

    RETURNS
        1 - Always returns true, regardless of configuration or context

    NOTES
        This rule is designed to always succeed. It can be used with any
        configuration value, but the configuration is ignored.

=back

=cut

around BUILDARGS => sub {
    my ( $orig, $class, @args ) = @_;

    return { config => 1 }
      if @args == 0 || ( @args == 1 && ( !ref $args[0] || ref $args[0] ne 'HASH' ) );

    return { config => $args[0] }
      if @args == 1 && ref $args[0] eq 'HASH';

      my %args = @args;
    return $class->$orig(%args);
};

=head2 is_allowed

Always returns true (1). This method ignores all configuration parameters
and context, making it suitable for unconditional allow scenarios.

The True rule is particularly useful in rule systems where you need:
- A guaranteed positive result for testing
- Default allow behavior when other conditions are not met
- Temporary bypass of complex rule logic during development
- Simple positive conditions in rule hierarchies

=cut

sub is_allowed ($self) {

    # Always return true - this rule never fails
    # The !!1 ensures we return a proper boolean true value
    return !!1;
}

1;

# END AUGMENT GENERATED CODE
