#------------------------------------------------------------
# Copyright (C) 2009 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package Support::Service::ServiceList;

use strict;
use warnings;
use Carp;

use Data::Dumper;

use lib '/app/tools/support/lib';
use Support::Service::DistributionService;
use Support::DB::Item::DistributionService;
use Support::Permission;

use lib '/app/tools/common/lib';
use Common::Assert;
use Common::DB::Item::MapFaceService;

use lib '/app/tools/distribution/lib';

use lib '/app/tools/support/lib';
use Support::Service::ServiceSimple;

use lib '/app/tools/data_classes/lib';
use Client::Service;

use Common::FormObject;
use base 'Common::FormObject';

sub _init {
    my ( $self, %args ) = @_;

    my $serviceID = $args{serviceID};

    $self->SUPER::_init(%args);

    my @services;

    if ($serviceID) {
        @services = ($serviceID);
    } else {
        @services = Client::Service::GetAllServiceIDs();
    }

    my @serviceList;
    my @serviceListSorted;

    foreach $serviceID (@services) {
        my $service = new Support::Service::ServiceSimple( serviceID => $serviceID );

        push( @serviceList, $service );
    }

    my $mapFaceServices = Common::DB::Item::MapFaceService->GetAll();
    while ( $mapFaceServices->hasNext() ) {
        my $mapFaceService = $mapFaceServices->next();
        my $service = new Support::Service::ServiceSimple( _dbItem => $mapFaceService );

        push( @serviceList, $service );
    }

    @serviceListSorted = ( sort @serviceList );

    $self->{Service} = \@serviceListSorted;

    return $self;
}

sub Services {
    my $self = shift;
    return @{ $self->{Service} };
}

1;
