#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package RPS::ArtistContract::ArtistContractList;

use strict;
use warnings;

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

use lib '/app/tools/rps/lib';
use RPS::ArtistContract::ArtistContract;

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

# This is a read-only XMLObject, so we don't need any
# of the accessor methods, just create the list of
# items and be on your way.
#

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

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

    $self->{ArtistContract} = [];
    my $coll;
    if ( $args{query} ) {
        $coll = RPS::DB::Item::NewArtistContract->SearchTitleAndClientContractID(
            searchTerm => $args{query},
            limit      => $args{limit},
            albumID    => $args{albumID},
            trackID    => $args{trackID}
        );
    } elsif ( $args{artistPayeeID} ) {
        $coll = RPS::DB::Item::NewArtistContract->GetByPayee( $args{artistPayeeID} );
    } elsif ( $args{payorID} ) {
        $coll = RPS::DB::Item::NewArtistContract->GetByPayor( $args{payorID} );
    }

    if ($coll) {
        while ( $coll->hasNext() ) {
            my $contractObj = $coll->next;
            push @{ $self->{ArtistContract} }, RPS::ArtistContract::ArtistContract->new( _dbItem => $contractObj, loadSubs => 0 );
        }
    }

    return $self;
}

1;

