#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long qw(:config no_ignore_case);
use Perun::Agent;
use Perun::Common qw(printMessage);

sub help {
	return qq{
	Adds a Vo manager. User id and vo id or vo short name are required fields.
	------------------------------------
	Available options:
	--voId        | -v vo id
	--voShortName | -V vo short name
	--userId      | -u user id
	--batch       | -b batch
	--help        | -h prints this help

	};
}

my ($voId, $userId, $voShortName, $batch);
GetOptions ("help|h" => sub { print help(); exit 0;} ,"batch|b" => \$batch,
"voId|v=i" => \$voId, "voShortName|V=s" => \$voShortName,
 "userId|u=i" => \$userId) || die help();

# Check options
unless (defined($voShortName) or defined($voId)) {die "ERROR: voId or voShortName is required\n";}
unless (defined($userId)) {die "ERROR: userId is required\n";}

my $agent = Perun::Agent->new();
my $vosAgent = $agent->getVosAgent;

if (!defined($voId)) {
	my $vo = $vosAgent->getVoByShortName(shortName => $voShortName);
	$voId = $vo->getId;
}

$vosAgent->addAdmin(vo => $voId, user => $userId);

printMessage("User Id:$userId successfully added as a Vo Id:$voId manager", $batch);
