package Whostmgr::CometBackup::Config;

#                                      Copyright 2026 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;

=head1 MODULE

C<Whostmgr::CometBackup::Config>

=head1 DESCRIPTION

C<Whostmgr::CometBackup::Config> is used to load the configuration file for the comet plugin.
This file contains various configuration options that are used by the plugin and its components.

=head1 SYNOPSIS

  use  Whostmgr::CometBackup::Config();
  my $config = Whostmgr::CometBackup::Config::load();

=head1 PRIVATE PROPERTIES

=head2 $_config

The cached configuration.

=cut

my $_config;

=head1 METHODS

=head2 load

Load the configuration. If already loaded, it will return the cached configuration..

=cut

sub load {
    if ( !$_config ) {

        my $config_file = '/var/cpanel/plugins/comet-backup/config.yaml';
        require YAML::XS;
        $_config = YAML::XS::LoadFile($config_file)
          or die sprintf( 'Failed to load %s with error: %s', $config_file, $! );
    }
    return $_config;
}

=head2 clear_cache

Clear the cached configuration. This is useful when you want to reload the configuration file.

=cut

sub clear_cache {
    $_config = undef;
}

1;
