package Cpanel::API::Plugins;

# cpanel - Cpanel/API/Plugins.pm                   Copyright 2024 cPanel, L.L.C.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

use cPstrict;
use Cpanel::Imports;

use Cpanel::Plugins::UUID     ();
use Cpanel::Validate::Boolean ();

our %API = (
    get_uuid   => { allow_demo => 0 },
    reset_uuid => { allow_demo => 0 },
);

=head1 MODULE

C<Cpanel::API::Plugins>

=head1 DESCRIPTION

C<Cpanel::API::Plugins> provides methods to interface with the common plugin framework.

=head1 FUNCTIONS

=head2 get_uuid()

Get the user's plugin UUID.

=head3 ARGUMENTS

=over

None.

=back

=head3 RETURNS

The cPanel user's UUID shared across plugins.

=over

=item uuid - string

=back

=head3 EXAMPLES

CLI ( Arguments must be uri escaped ):

uapi --user=cpanel_user Plugins get_uuid

TT:

 [%
     SET result = execute( 'Plugins', 'get_uuid', );
     SET uuid = result.data.uuid;
 %]

=cut

sub get_uuid ( $args, $result ) {

    my $uuid = Cpanel::Plugins::UUID->new();
    $result->data( { uuid => $uuid->uuid } );

    return 1;
}

=head2 reset_uuid()

Reset the user's plugin UUID and optionally generate and return a new one.

=head3 ARGUMENTS

=over

None.

=back

=head3 RETURNS

The cPanel user's UUID shared across plugins.

=over

=item uuid - string

=back

=head3 EXAMPLES

CLI ( Arguments must be uri escaped ):

uapi --user=cpanel_user Plugins reset_uuid

TT:

 [%
     SET result = execute( 'Plugins', 'reset_uuid', );
     SET uuid = result.data.uuid;
 %]

=cut

sub reset_uuid ( $args, $result ) {

    my $uuid = Cpanel::Plugins::UUID->new();
    $result->data( { uuid => $uuid->reset() } );

    return 1;
}

1;
