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

use Cpanel::Server::Type ();

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

=head1 MODULE

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

=head1 DESCRIPTION

Evaluates if the current server's is licensed as DNS Only.

This class is used if the rules config file includes a 'dnsonly' in the rule.

=head1 SYNOPSIS

Check if the server is running under a DNS Only license:

  use Cpanel::Plugins::Components::Rules::DnsOnly ();
  my $return = Cpanel::Plugins::Components::Rules::DnsOnly->new()->is_allowed();


When you are using the declaritive JSON syntax:

  {
    "dns-only": true
  }

=cut

=head1 METHODS

=over

=item * is_allowed -- Allow the campaign if rules are met.

    RETURNS
        0 - The server is NOT running under a DNS Only license.
        1 - The server is running under a DNS Only license.

=back

=cut

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

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

    # ( [ 1 ] )
    return { config => $args[0] }
      if @args == 1 && ref $args[0];

    # ( config => 1 ) ... ( config => [1] )
    my %args = @args;
    $args{config} = [ $args{config} ] if !ref $args{config};
    return $class->$orig(%args);
};

sub is_allowed ($self) {
    return !!1 if Cpanel::Server::Type::is_dnsonly();
    return !!0;
}

1;
