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

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::SearchCommand;
use base 'RPS::SearchCommand';

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

use constant kTemplate => "/app/tools/rps/templates/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("AlbumID"))
	{
		$self->{xml}{AlbumContractList} = RPS::Catalog::AlbumContractList->new(albumID => $self->getParam("AlbumID"));
	}
    elsif ($self->getParam("TrackID"))
    {
		$self->{xml}{TrackContractList} = RPS::Track::TrackContractList->new(trackID => $self->getParam("TrackID"));
    }

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

	return $response;
}



1;
