#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::Statement::Mechanical::StatementLicenseList;

use strict;
use warnings;
use Carp;

use Data::Dumper;

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

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

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

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

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

    my $statementID = $args{mechanicalStatementID};
    my $trackID     = $args{trackID};
    my $publisherID = $args{publisherID};
    my $crossedFlag = $args{crossed};

    $self->{MechanicalStatementLicense} = [];
    if ($statementID) {

        my $collection;
        if ($publisherID) {
            $collection = $self->_getStatementLicenseCollectionByPublisherID( $statementID, $trackID, $publisherID );
        } else {
            $collection = $self->_getStatementLicenseCollection( $statementID, $trackID );
        }

        while ( $collection->hasNext() ) {
            my $obj = $collection->next();

            next if ( $crossedFlag  && !$obj->crossed );
            next if ( !$crossedFlag && $obj->crossed );

            push @{ $self->{MechanicalStatementLicense} }, $self->_getStatementLicense($obj);
        }
    }

    return $self;
}

sub _getStatementLicenseCollectionByPublisherID {
    my ( $self, $statementID, $trackID, $publisherID ) = @_;
    assert( 0, 'override this' );
}

sub _getStatementLicenseCollection {
    my ( $self, $statementID, $trackID ) = @_;
    assert( 0, 'override this' );
}

sub _getStatementLicense {
    my ( $self, $dbItem ) = @_;
    assert( 0, 'override this' );
}

sub getList {
    my ($self) = @_;

    return $self->{MechanicalStatementLicense};
}

1;
