package Cpanel::Config::ConfigObj::Driver::Sitejet;

# cpanel - Cpanel/Config/ConfigObj/Driver/Sitejet.pm
#                                      Copyright 2024 WebPros International, LLC
#                                                            All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited.

use cPstrict;

=encoding utf-8

=head1 NAME

Cpanel::Config::ConfigObj::Driver::Sitejet

=head1 DESCRIPTION

Feature Showcase driver for Sitejet

=cut

use parent qw(Cpanel::Config::ConfigObj::Interface::Config::v1);

use Cpanel::Config::ConfigObj::Driver::Sitejet::META ();
use Cpanel::Imports;

*VERSION = \$Cpanel::Config::ConfigObj::Driver::Sitejet::META::VERSION;

=head1 METHODS

=head2 init

Initializes the feature showcase object.

=cut

sub init ( $class, $software_obj ) {

    my $defaults = {
        'settings'      => {},
        'thirdparty_ns' => "",
    };

    my $self = $class->SUPER::base( $defaults, $software_obj );

    return $self;
}

=head2 set_default

We want this checked by default.

=cut

sub set_default {

    # please note spotlight_features & recommended_features have default options as enabled
    return is_beta_enabled_based_on_rules();
}

# for additional info, refer Cpanel::Config::ConfigObj::Interface::Config::v1 for definition
# this has to be set undef for set_default to work
sub check { return undef; }

=head2 enable

Locally enable Sitejet Beta

B<Note>: The Sitejet Beta will be locally enabled only if they have it disabled.

=cut

sub enable {
    my ($self) = @_;
    my $default = is_beta_enabled_based_on_rules();
    return 1 if $default;

    # override only if the beta is not already enabled
    require Cpanel::Sitejet::Beta::Setup;
    Cpanel::Sitejet::Beta::Setup::local_enable();

    return 1;
}

=head2 disable

Locally disable Sitejet Beta

B<Note>: The Sitejet Beta will be locally disabled only if they have it enabled.

=cut

sub disable {
    my ($self) = @_;

    my $default = is_beta_enabled_based_on_rules();
    return 1 if !$default;

    # override only if the beta is not already disabled
    require Cpanel::Sitejet::Beta::Setup;
    Cpanel::Sitejet::Beta::Setup::local_disable();
    return 1;
}

=head2 is_beta_enabled_based_on_rules

Process beta rules and return the status

=cut

sub is_beta_enabled_based_on_rules() {
    require Cpanel::Template::Plugin::Sitejet;
    return Cpanel::Template::Plugin::Sitejet::get_is_beta();
}
1;
