#------------------------------------------------------------
# Copyright (C) 2011 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package BookPub::DB::Item::ServiceCredential;
use strict;
use warnings;

use lib '/app/tools/bookpub/lib';
use BookPub::DB::Item::Sale;

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

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

sub GetByServiceID {
    my $class = shift;
    my %args  = @_;

    my $serviceID = $args{service_id};

    assert($serviceID);

    my $sql = "SELECT * FROM " . kTable . " WHERE service_id = " . $class->quote($serviceID);

    my $collection = $class->SUPER::GetAll($sql);

    die("More than set of credentials found for service") if ( $collection->size() > 1 );

    return $collection->next();
}

sub GetAllServiceCredentialIDs {
    my $class = shift;

    my $sql = "SELECT service_credential_id FROM " . kTable;

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

1;
