#------------------------------------------------------------
# Copyright (C) 2011 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package Support::DB::Item::BookPubServiceCredential;
use strict;
use warnings;

use Data::Dumper;

use lib '/app/tools/rps/lib';

use lib '/app/tools/common/lib';
use Common::Assert;

use base 'Common::DB::Item';

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

sub GetAllServiceCredentials {
    my $class = shift;

    my $sql = "SELECT s.service_name, sc.* FROM service_credential sc ";
    $sql .= "JOIN service s ";
    $sql .= "ON sc.service_id = s.service_id ";

    return $class->SUPER::GetAll($sql);
}

sub GetServiceCredentialByID {
    my ( $class, %args ) = @_;
    my $id = $args{service_credential_id};

    my $sql = "SELECT s.service_name AS service_name, sc.* ";
    $sql .= "FROM service_credential sc ";
    $sql .= "JOIN service s ";
    $sql .= "ON sc.service_id = s.service_id ";
    $sql .= "WHERE sc.service_credential_id = $id";

    my $collection = $class->SUPER::GetAll($sql);
    my $tmp        = $collection->next();
    return $tmp;
}

sub GetAllServiceCredentialIDs {
    my $class = shift;

    my $sql        = "SELECT service_credential_id FROM service_credential";
    my $collection = $class->SUPER::GetAll($sql);

    my @idArray = ();
    while ( my $item = $collection->next() ) {
        push @idArray, $item->service_credential_id;
    }

    return @idArray;
}

1;
