package RSWS::ClientInfo;
use strict;

use base 'RSWS';

sub clientType {
    my $self = shift;
    $self->{reqArgs}{type} = shift;
    $self->{argsSet} = 1;
}

sub _init {
    my $self = shift;

    $self->{xmlSimple} = XML::Simple->new();
}

sub _requestURL {

    # although data comes from RSCOMMON (on raptor01), either rps box can access it
    #return 'https://dev02.royaltyshare.com/rsws/clientinfo'; # for testing
    return 'https://rps01.royaltyshare.com/rsws/clientinfo';
}

sub _requestArgs {
    my $self = shift;
    return $self->{argsSet} ? $self->{reqArgs} : undef;
}

sub _responseHandler {
    my $self     = shift;
    my $response = shift;

    return undef unless ( length $response );

    #print $response, "\n";
    #exit();
    my $dataRef = $self->{xmlSimple}->XMLin($response);
    unless ( ref $dataRef ) {
        $self->error('failed to parse response');
        return undef;
    }

    my %clients = ();

    foreach my $record ( @{ $dataRef->{Client} } ) {
        $clients{ $record->{ClientID} }{name} = $record->{ClientName}{content};
        $clients{ $record->{ClientID} }{host} = $record->{DBHost}{content};
    }

    return \%clients;
}

1;
