#!/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{
	Deletes a Vo. Vo id or vo short name are required fields.
	------------------------------------
	Available options:
	--voId        | -v vo id
	--voShortName | -V vo short name
	--force       | -f delete also all dependent data
	--batch       | -b batch
	--help        | -h prints this help

	};
}

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

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

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

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

if (defined($force)) {
	$vosAgent->deleteVo( vo => $voId, force => 1 );
} else {
	$vosAgent->deleteVo( vo => $voId );
}

printMessage("Vo Id:$voId successfully deleted", $batch);
