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

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

use lib '/app/tools/rps/lib';
use RPS::Track::TrackListWithCALicenses;
use RPS::Catalog::AlbumControlledCompContractList;
use RPS::DB::Item::CATrackLicense;
use RPS::Region::RegionList;
use RPS::Product::TypeList;
use RPS::Product::ProductList;
use RPS::RoyaltyRun::RoyaltyRunStatusList;

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


sub GetNumLicenses
{
    my ($albumID) = @_;

    my $collection = RPS::DB::Item::CATrackLicense->GetLicensesByAlbumID($albumID);
    return $collection->size();
}

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

    assert($args{albumID});

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


    # Basically, I just want a track list that contains all the track licenses.
    # Should be able to re-use objects I already have.
    #
    # !!! This form has a filter (two, actually).  So I need to be able to pass that along.
    #
    $self->{TrackList} = RPS::Track::TrackListWithCALicenses->new(
							albumID => $args{albumID},
							filter => { productFilter => $args{productFilter},
						                licenseFilter => $args{licenseFilter} } );


    # Need the list of contracts, and some way to indicate which is the controlled comp.
    # !!! Can probably filter out contracts without the controlled comp clause
    #
    $self->{AlbumContractList} = RPS::Catalog::AlbumControlledCompContractList->new(albumID => $args{albumID});


    # License have region and product ids stored in them, so we need the full lists to map those to names.
    #
    #
    $self->{RegionList} = RPS::Region::RegionList->new();
    $self->{TypeList} = RPS::Product::TypeList->new(includeTrackProducts => 1);
    $self->{ProductList} = RPS::Product::ProductList->new(albumID => $args{albumID}, loadSubs => 0);
	#$self->{RoyaltyRunStatus} = RPS::RoyaltyRun::RoyaltyRunStatusList->new( caMechanical => 1 );
	$self->{RoyaltyRunStatus} = RPS::RoyaltyRun::RoyaltyRunStatusList->new( caMechanical => 1 );

	return $self;
}



###
1;#
###
