#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package BookPub::DB::Item::ClientService;

use strict;
use warnings;

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

use constant kTable => 'client_service';
use constant kDB    => Common::DB::Item::kClientDB;

sub GetProductTypes {
    my $class = shift;
    my $list  = $class->GetAll( 'SELECT DISTINCT(IFNULL(product_type,"ANY")) AS product_type FROM ' . kTable );

    my @typeList = ();
    while ( my $type = $list->next() ) {
        push @typeList, $type->product_type;
    }

    return \@typeList;
}

sub GetAllByRSServiceIDProdTypeCurrencyCode {
    my $class = shift;
    my $list  = $class->GetAll();

    my %serviceMap = ();
    while ( my $svc = $list->next() ) {
        my $pType = $svc->product_type || 'ANY';
        $serviceMap{ $svc->service_id }{$pType}{ $svc->currency_code }{ $svc->feed_id } =
          { id => $svc->client_service_id, name => $svc->name };
    }

    return \%serviceMap;
}

1;
