#!/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{
	Creates a vo. Vo full and short name are required fields.
	--------------------------------------
	Available options:
	--voFullName   | -n vo full name
	--voShortName  | -V vo short name (max. 16 characters)
	--batch        | -b batch
	--help         | -h prints this help

	};
}

my ($voFullName, $voShortName, $batch);
GetOptions ("help|h" => sub {
		print help();
		exit 0;
	}, "batch|b"     => \$batch,
	"voFullName|n=s" => \$voFullName, "voShortName|V=s" => \$voShortName) || die help();

# Check options
unless (defined($voFullName)) { die "ERROR: voFullName is required \n";}
unless (defined($voShortName)) { die "ERROR: voShortName is required \n";}
unless ($voFullName !~ /^\s*$/) { die "ERROR: voFullName cannot be empty string\n";}
unless ($voShortName !~ /^\s*$/) { die "ERROR: voShortName cannot be empty string\n";}

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

my $vo = Perun::beans::Vo->new;
$vo->setName( $voFullName );
$vo->setShortName( $voShortName );

$vo = $vosAgent->createVo( vo => $vo );

printMessage("Vo Id:".$vo->getId." successfully created", $batch);
