#!/usr/bin/perl -X
require '/var/www/EventStaffAPI/UnitTest/UnitTest_Globals.pl';

$HTTP = $ARGV[0];
$DEBUG = $ARGV[1];


##Test 1
$xml = "<\?xml version=\"1.0\"\?>";
$xml .="<fwxg_api> 
<api_action>retrieve_api_descriptor</api_action>
<action_content>
</action_content>
</fwxg_api>
";

$receivedHash = DoHTTPCall($xml);

##Test 1
$xml = "<\?xml version=\"1.0\"\?>";
$xml .="<fwxg_api>
<api_action>user_functions_get_agency_from_domain</api_action>
<action_content>
 <domain>predetorlinux.dedicated.co.za</domain>
</action_content>
</fwxg_api>
";

$receivedHash = DoHTTPCall($xml);

####RETURN_CHECKS####
if($receivedHash->{status} ne "true") { print "Call Returned Failed \@ Line(".__LINE__.")\n"; exit(-1); }
$agency_id = $receivedHash->{agency_id};

##Test 1
$xml = "<\?xml version=\"1.0\"\?>";
$xml .="<fwxg_api>
<api_action>user_functions_user_list</api_action>
<action_content>
 <agency_id>$agency_id</agency_id>
</action_content>
</fwxg_api>
";

$receivedHash = DoHTTPCall($xml);

####RETURN_CHECKS####
if($receivedHash->{status} ne "true") { print "Call Returned Failed \@ Line(".__LINE__.")\n"; exit(-1); }

##Test 1
$xml = "<\?xml version=\"1.0\"\?>";
$xml .="<fwxg_api>
<api_action>user_functions_user_type_list</api_action>
<action_content>
</action_content>
</fwxg_api>
";

$receivedHash = DoHTTPCall($xml);

####RETURN_CHECKS####
if($receivedHash->{status} ne "true") { print "Call Returned Failed \@ Line(".__LINE__.")\n"; exit(-1); }

##Test 1
$xml = "<\?xml version=\"1.0\"\?>";
$xml .="<fwxg_api>
<api_action>user_functions_login</api_action>
<action_content>
 <agency_id>$agency_id</agency_id>
 <username>agency1_admin</username>
 <password>predetor</password> 
</action_content>
</fwxg_api>
";

$receivedHash = DoHTTPCall($xml);

####RETURN_CHECKS####
if($receivedHash->{status} ne "true") { print "Call Returned Failed \@ Line(".__LINE__.")\n"; exit(-1); }
$session_id = $receivedHash->{session_id};

##Test 1
$xml = "<\?xml version=\"1.0\"\?>";
$xml .="<fwxg_api>
<api_action>user_functions_agency_user_list</api_action>
<action_content>
 <session_id>$session_id</session_id>
 <agency_users>1</agency_users>
 <client_users>1</client_users>
 <event_staff_users>1</event_staff_users>
</action_content>
</fwxg_api>
";

$receivedHash = DoHTTPCall($xml);

####RETURN_CHECKS####
if($receivedHash->{status} ne "true") { print "Call Returned Failed \@ Line(".__LINE__.")\n"; exit(-1); }

exit(0);