#!/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{
	Lists users assigned to Specific user. Specific user id is required.
	--------------------------------------
	Available options:
	--specUserId   | -u specific user id
	--batch        | -b batch
	--help         | -h prints this help

	};
}

my ($specUserId, $batch);
GetOptions ("help|h"  => sub {
		print help();
		exit 0;
	}, "batch|b"        => \$batch,
	"specUserId|u=i"    => \$specUserId ) || die help();

# Check options
unless (defined($specUserId)) { die "ERROR: userId is required \n";}

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

my @users=$usersAgent->getUsersBySpecificUser( specificUser => $specUserId );

unless (@users) {
	printMessage "No users found", $batch;
	exit 0;
}

#output
my $sortingFunction = getSortingFunction("getSortingName", 1);
printTable($sortingFunction, @users);

