#!/usr/bin/perl
package Existsuser;
use strict;
use Data::Dumper;
use base qw(BasicCommandlineOptions);


#Use the SOAP::Lite Perl module
#use SOAP::Lite +trace => 'debug';
use SOAP::Lite;

my $test = new Existsuser();
$test->doRequest();

sub new {
  my ($inPkg) = @_;
  my $self = BasicCommandlineOptions->new();
	
  bless $self, $inPkg;
  return $self;
}

sub doRequest {
  my $inSelf = shift;
  my $soap = SOAP::Lite->ns( $inSelf->{'serviceNs'} )->proxy( $inSelf->{'basisUrl'}."OXUserService" );
  my $exists = "testuser";
  my $notexists = "rumpelstilz";

  my $retexists = "false";
  my $retnotexists = "false";

  my $som_entry = 
    $soap->exists($inSelf->{'Context'},
		  SOAP::Data->name("User" => \SOAP::Data->value(
			SOAP::Data->name("name" => $exists)
   	          )),
		  $inSelf->{'creds'}
		 );
    
  if ( $som_entry->fault() ) {
    $inSelf->fault_output($som_entry);
    exit(1);
  } else {
    $retexists = $som_entry->paramsall;
  }

  $som_entry = 
    $soap->exists($inSelf->{'Context'},
		  SOAP::Data->name("User" => \SOAP::Data->value(
			SOAP::Data->name("name" => $notexists)
   	          )),
		  $inSelf->{'creds'}
		 );
    
  if ( $som_entry->fault() ) {
    $inSelf->fault_output($som_entry);
    exit(1);
  } else {
    $retnotexists = $som_entry->paramsall;
  }

  if( $retexists eq "true" && $retnotexists eq "false" ) {
      print "Fine\n";
  } else {
    exit(1);
  }


}

exit;

