#!/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

use cPstrict;

use Test2::V0;
use Test2::Tools::Explain;
use Test2::Plugin::NoWarnings;
use Test2::Tools::Subtest;
use Test2::Tools::Exception;
use Test2::Tools::Ref;

use Test::MockModule qw/strict/;
use Test::MockFile   qw/strict/;

use Test::Cpanel::Policy testing => 'Cpanel::Plugins::Components::Rules';

use Cpanel::Plugins::Components::Rules::Util::NVData;

my $mock_personalization = Test::MockModule->new("Whostmgr::API::1::Personalization");
$mock_personalization->redefine(
    'personalization_set' => sub {
        my $response = {
            'personalization' => {
                'key' => {
                    'value'   => 'val',
                    'success' => 1,
                    'reason'  => 'OK',
                }
            },
        };
        return $response;
    },
    'personalization_get' => sub {
        my $response = {
            'personalization' => {
                'key' => {
                    'value'   => 'val',
                    'success' => 1,
                    'reason'  => 'OK',
                }
            },
        };
        return $response;
    }
);

subtest 'Verify set_get_nv_data' => sub {
    my $store = 'example-nvdata';
    my $key   = 'key';
    my $value = 'val';

    my $set = Cpanel::Plugins::Components::Rules::Util::NVData::set_nv_data( $store, $key, $value );
    my $get = Cpanel::Plugins::Components::Rules::Util::NVData::get_nv_data( $store, $key );
    is $set, 1,      'set_nv_data calls Whostmgr::API::1::Personalization::personalization_set';
    is $get, $value, 'get_nv_data calls Whostmgr::API::1::Personalization::personalization_get';
};

done_testing;
