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

use strict;
use warnings;
use Carp;

use Data::Dumper;

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

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

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

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

    my %properties;
    if ( $args{_dbItem} ) {
        $self->_propertiesFromDBItem( \%properties, $args{_dbItem} );
    } elsif ( $args{mechanicalStatementPublisherID} ) {
        $self->_propertiesFromDB( \%properties, $args{mechanicalStatementPublisherID} );
    } else {
        $self->_propertiesFromDefaults( \%properties );
    }

    # !!! This is not ideal, really, but I don't see a better way.
    #
    my $showTracks = $args{showTracks};

    $self->_initProperties( \%properties, $showTracks );

    return $self;
}

sub _propertiesFromDB {
    my ( $self, $hrProperties, $id ) = @_;

    assert( 0, 'override this' );
}

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

sub _initProperties {
    my ( $self, $props, $showTracks ) = @_;

    # Assume USD for now
    #
    my $currencyCode = $self->_getCurrencyCode();

    $self->{MechanicalStatementPublisherID} =
      Common::FormObject::Scalar->new( value => $props->{mechanical_statement_publisher_id}, readOnly => 1 );
    $self->{MechanicalStatementID} = Common::FormObject::Scalar->new( value => $props->{mechanical_statement_id}, readOnly => 1 );
    $self->{PublisherID}           = Common::FormObject::Scalar->new( value => $props->{publisher_id},            readOnly => 1 );
    $self->{PublisherSubtotal} = Common::FormObject::Scalar::Money->new( value => $props->{subtotal}, currencyCode => $currencyCode );
    $self->{Publisher} = $self->_publisher()->new( publisherID => $props->{publisher_id} );

    $self->{TransactionSubtotal} = Common::FormObject::Scalar::Money->new( value => $props->{transaction_subtotal} );
    $self->{PreviousBalance}     = Common::FormObject::Scalar::Money->new( value => $props->{previous_balance} );
    $self->{StatementTotal}      = Common::FormObject::Scalar::Money->new( value => $props->{statement_total} );
    $self->{AmountDue}           = Common::FormObject::Scalar::Money->new( value => $props->{amount_due} );
    $self->{OnHold} = Common::FormObject::Scalar->new( value => $props->{on_hold} );

    $self->{MechanicalStatementPublisherTransactionList} =
      $self->_getStatementPublisherTransactionList( $props->{mechanical_statement_id}, $props->{publisher_id} );

    if ($showTracks) {
        $self->{MechanicalStatementTrackList} = $self->_getStatementTrackList( $props->{mechanical_statement_id}, $props->{publisher_id} );
    }
}

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

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

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

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

    return $self->{MechanicalStatementTrackList}->getList();
}

sub _propertiesFromDefaults {
    my ( $self, $hrProperties ) = @_;
}

###
1;    #
###

