#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::DB::Item::CAMechanicalStatementPublisherTransaction;
use strict;
use warnings;
use lib '/app/tools/common/lib';
use Common::Assert;
use Common::DB::Item;
use base 'Common::DB::Item';

use constant kTable => 'ca_mechanical_statement_publisher_transaction';
use constant kDB    => Common::DB::Item::kClientDB();

sub GetByMechanicalStatementID {
    my ( $class, $stmtID ) = @_;
    assert($stmtID);

    my $sql = "SELECT * FROM " . kTable . " WHERE ca_mechanical_statement_id=$stmtID";
    return $class->GetAll($sql);
}

sub GetByMechanicalStatementAndPublisherID {
    my ( $class, $statement_id, $publisher_id ) = @_;

    my $sql = "SELECT * FROM " . kTable . " WHERE ca_mechanical_statement_id=$statement_id AND ca_publisher_id=$publisher_id";
    return $class->GetAll($sql);
}

sub DeleteByMechanicalStatementID {
    my ( $class, $id ) = @_;

    my $sql = "DELETE from " . kTable . " WHERE ca_mechanical_statement_id=$id";
    my $dbo = Common::RSApp::GetClientDB();
    $dbo->DoCmd($sql);
}

sub GetSubPublisherIDs {
    my ( $class, $statementID ) = @_;
    my $dbo = Common::RSApp::GetClientDB();

    my $sql = "SELECT DISTINCT ca_publisher_id FROM " . kTable . " WHERE ca_mechanical_statement_id = $statementID";

    my $sth = $dbo->DoCmd($sql);

    my @result;
    if ($sth) {
        while ( my $id = $sth->fetchrow_array() ) {
            push @result, $id;
        }
    }

    return @result;
}

1;
