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

use strict;
use warnings;
use Carp;

use Data::Dumper;
use lib '/app/tools/common/lib';
use Common::FormObject;
use Common::Assert;


use base 'Common::FormObject';

sub _getStatementCollection
{
    my ($self, $runID, $payorID, $filterBy) = @_;
    assert(0, 'override this');
}

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

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

    $self->{MechanicalStatement} = [];

    my $runID = $args{mechanicalRunID};
    my $payorID = $args{payorID};
    assert($runID);
    assert($payorID);

    my $filterBy = $args{filterBy};

    my $collection = $self->_getStatementCollection($runID, $payorID, $filterBy);


    if ($collection)
    {
		while ($collection->hasNext())
		{
			my $obj = $collection->next();

            # Calling an abstract member function to actually create the correct
            # subclass of BaseMechanicalStatement.
            #
			push @{$self->{MechanicalStatement}}, $self->_makeStatement($obj);
		}
	}

    return $self;
}



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

sub _listProperties
{
    return { MechanicalStatement => 1 };
}


sub MechanicalStatement 
{
    my ($self, $index, $methodAddressList, $newValue) = @_;

    if (0 == scalar @$methodAddressList)
    {
        if (defined $newValue)
        {
            $self->{MechanicalStatement}[$index] = $newValue;
        }
        return 1;
    }

    # May need to dynamically add objects to the list...
    #
    if (! defined $self->{MechanicalStatement}[$index])
    {
        die "ERROR - no mechanical statement with index $index";
    }

    return $self->{MechanicalStatement}[$index]->_accessProperty($methodAddressList, $newValue);
}



1;
