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

# !!! Re-writing this to include both Album and Track contracts.
# Basically, this is going to be totally redone.
#

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

use lib '/app/tools/rps/lib';
use RPS::Catalog::AlbumContractWithArtistContractList;
use RPS::Track::TrackListWithContracts;
use RPS::RoyaltyRun::RoyaltyRunStatusList;

use RPS::DB::Item::AlbumContract;
use RPS::DB::Item::TrackContract;

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

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

    assert($args{albumID});

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

    # We want to display all the album contracts attached to this album.
    #
    $self->{AlbumContractList} = RPS::Catalog::AlbumContractWithArtistContractList->new(albumID => $args{albumID});

    # We also want to display all the track contracts attached to tracks on this album.
    # So... the Track::TrackContractList will list all the contracts for a given track.
    # If you pass in a trackID to that guy, it will fetch and return all the contracts, but
    # won't repeat the track XML (which is good for us).
    # We'll need to provide the track XML here.
    #
    # I think I'll just wrap all that stuff up in another object.
    #
    $self->{TrackList} = RPS::Track::TrackListWithContracts->new(albumID => $args{albumID});

	$self->{RoyaltyRunStatus} = RPS::RoyaltyRun::RoyaltyRunStatusList->new(
									artist => 1, caMechanical => 1, usMechanical => 1 );

	return $self;
}


# This is a static method that returns the number of album and track contracts
# attached to an album
#
sub GetNumContracts
{
    my ($albumID) = @_;

    # This is more efficient than it might look.
    # The DB::ItemCollection class is lazy, so it won't be
    # fetching the entire collection at once. So there won't
    # be a lot of wasted effort here.
    #
    my $albumCollection = RPS::DB::Item::AlbumContract->GetByAlbumID($albumID);
    my $trackCollection = RPS::DB::Item::TrackContract->GetByAlbumID($albumID);

    return ($albumCollection->size() + $trackCollection->size());
}

###
1;#
###
