#!/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 TemplateMessages.
---------------------------------------
Available options:
 --orderByTemplateId | -t order by templateId
 --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') },
	"orderByTemplateId|t" => sub {$sortingFunction = getSortingFunction("getTemplateId", 1); } ) || die help;

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

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

printTable($sortingFunction, @objects);
