#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long qw(:config no_ignore_case);
use Perun::Agent;
use Perun::Common qw(printMessage getSortingFunction printTable);
use Text::ASCIITable;
use Switch;

sub help {
	return qq{
	Returns state of the GEN and SEND services on the defined destinations
	---------------------------------------------------------------
	Available options:
	--destinations   | -d destinations separated by space
	--batch          | -b batch
	--help           | -h prints this help

	};
}

my (@destinations);
our $batch;
GetOptions ("help|h"        => sub {
		print help();
		exit 0;
	}, "batch|b"            => \$batch,
	'destinations|d=s@{1,}' => \@destinations) || die help();

# Check options
unless (@destinations) { die "ERROR: at least one destination must be specified\n";}

my $agent = Perun::Agent->new();
my $tasksAgent = $agent->getTasksAgent;

my @taskResults = $tasksAgent->getTaskResultsForDestinations( destinations => \@destinations );
unless (@taskResults) {
	printMessage "No tasks results found", $batch;
	exit 0;
}

my $sortingFunction = getSortingFunction("getDestinationName", 1);

printTable($sortingFunction, @taskResults);
