#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package RPS::ArtistContract::Command::Search;
use strict;
use warnings;

use lib '/app/tools/common/lib';
use RSApache::Response::XSLT;

use lib '/app/tools/rps/lib';
use RPS::Catalog::AlbumContractList;
use RPS::Track::TrackContractList;
use RPS::Payor::PayorList;

use RPS::SearchCommand;
use base 'RPS::SearchCommand';

sub cmd  { return 'search'; }
sub area { return 'artist_contract'; }

use constant kTemplate => "/app/tools/rps/templates/artist_contract/index.xsl";

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

    my $response = $self->SUPER::execute(
        dbClass  => 'RPS::DB::Item::NewArtistContract',
        xmlClass => 'RPS::ArtistContract::ArtistContract',
        xmlTag   => 'Contract',
        pageSize => 30
    );
    return $response if $response;

    # the presence of an AlbumID means we are trying to attach a contract
    # to an album, in which case we need to know which contracts have
    # already been attached to this album, so...
    #
    # we need to insert the album/contract list here
    #
    if ( $self->getParam("FullContractInfo") && $self->getParam("AlbumID") ) {
        $self->{xml}{AlbumContractList} = RPS::Catalog::AlbumContractList->new( albumID => $self->getParam("AlbumID") );
        $self->{xml}{TrackContractList} = RPS::Track::TrackContractList->new( albumID => $self->getParam("AlbumID") );
    }
    elsif ( $self->getParam("AlbumID") ) {
        $self->{xml}{AlbumContractList} = RPS::Catalog::AlbumContractList->new( albumID => $self->getParam("AlbumID") );
    }
    if ( $self->getParam("TrackID") ) {
        $self->{xml}{TrackContractList} = RPS::Track::TrackContractList->new( trackID => $self->getParam("TrackID") );
    }
    $self->{xml}{PayorList} = RPS::Payor::PayorList->new();

    $response = RSApache::Response::XSLT->new( $self->{xml}, kTemplate );

    return $response;
}

1;
