#!/usr/bin/perl

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

sub help {
return qq{
Prints list of all Notif Templates.
---------------------------------------
Available options:
 --orderByName  | -n order by name
 --orderById    | -i order by id (default)
 --batch        | -b batch
 --help         | -h prints this help
 
};
}

my $sortingFunction;
our $batch;
GetOptions ("help|h" => sub { print help; exit 0;} ,"batch|b" => \$batch, "orderById|i" => sub { $sortingFunction = getSortingFunction('getId') },"orderByName|n" => sub {$sortingFunction = getSortingFunction("getName", 1); } ) || die help; 

unless(defined $sortingFunction) { $sortingFunction = getSortingFunction("getId"); }

my $agent = Perun::Agent->new();
my $notifAgent = $agent->getNotificationsAgent;
my @objects = $notifAgent->getAllPerunNotifTemplates;
unless(@objects) { printMessage "No NotifTemplates found", $batch;  exit 0;}

printTable($sortingFunction, @objects);
