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

use strict;
use warnings;
use Carp;

use Data::Dumper;

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

use lib '/app/tools/rps/lib';

use RPS::DB::Item::Publisher;

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

# This is going to be a bit tricker...
# We do not have a corresponding table in the database.
# Instead, I need to make a query to determine how many publishers
# will be reported on in this statement.
#  That means a rather nasty query via track license.
# - I need to get all the unique publisher ids associated with all the track licenses that are
#   going to appear on this statement.

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

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

	my $id = $args{mechanicalStatementID};
    my $focusPublisherID = $args{focusPublisherID};

    $self->{MechanicalStatementPublisher} = [];
	if ($id)
	{
        my $publisherItems = $self->_getPublisherItemCollection($id);
        while (my $publisherItem = $publisherItems->next())
        {
            my $pub = $self->_getStatementPublisher($publisherItem, $focusPublisherID);

            assert($pub);
			push @{$self->{MechanicalStatementPublisher}}, $pub;
        }

        @{$self->{MechanicalStatementPublisher}} = sort {$a->{Publisher}->PublisherName cmp $b->{Publisher}->PublisherName } @{$self->{MechanicalStatementPublisher}};
	}

    return $self;
}

sub _getPublisherItemCollection
{
    my ($self, $statementID) = @_;
    assert(0, 'override this');
}

sub _getStatementPublisher
{
    my ($self, $publisherItem, $focusPublisherID) = @_;
    assert(0, 'override this');
}

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

    return $self->{MechanicalStatementPublisher};
}



1;
