#!/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 printTable getSortingFunction);

sub help {
	return qq{
	Prints list of users.
	------------------------------
	Available options:
	--orderById    | -i  order by user's identifier
	--orderByName  | -n  order by user's name
	--batch        | -b  batch
	--help         | -h  prints this help
	};
}

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

my $agent = Perun::Agent->new();
my $usersAgent = $agent->getUsersAgent;

#options check
unless(defined $sortingFunction) { $sortingFunction = getSortingFunction("getLastName", 1); }

my @users = $usersAgent->getUsersWithoutVoAssigned();
unless(@users) { printMessage "No users found", $batch; exit 0; }

print printTable($sortingFunction, @users);
