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

use strict;
use warnings;

use lib '/app/tools/rps/lib';
use RPS::Statement::Artist::BaseStatement;
use RPS::Statement::Mechanical::US::BaseStatement;
use RPS::Statement::Mechanical::CA::BaseStatement;
use RPS::Statement::UKMechanical::BaseStatement;
use RPS::Statement::Label::BaseStatement;

use Common::FormObject;
use RPS::CommandLog;

#use base 'Common::XMLObject';
use base 'RPS::CommandLog';

sub _createLogItemFromDBItem {
    my ( $self, $dbItem ) = @_;

    # First call the inherited method to get the log item
    #
    my $logItem = $self->SUPER::_createLogItemFromDBItem($dbItem);

    if ( 'RPS::Statement::Command::ShowArtist' eq $logItem->CommandName() ) {
        my $obj = RPS::Statement::Artist::BaseStatement->new( artistRoyaltyStatementID => $logItem->CommandID() );
        $logItem->{ArtistRoyaltyStatement} = $obj;
    } elsif ( 'RPS::Statement::Command::ShowMechanical' eq $logItem->CommandName()
        || 'RPS::Statement::Command::ShowMechanicalPDF' eq $logItem->CommandName() ) {
        my $obj = RPS::Statement::Mechanical::US::BaseStatement->new( mechanicalStatementID => $logItem->CommandID() );
        $logItem->{MechanicalStatement} = $obj;
    } elsif ( 'RPS::Statement::Command::ShowUKMechanical' eq $logItem->CommandName() ) {
        my $obj = RPS::Statement::UKMechanical::BaseStatement->new( mcpsStatementID => $logItem->CommandID() );
        $logItem->{McpsStatement} = $obj;
    } elsif ( 'RPS::Statement::Command::ShowCAMechanical' eq $logItem->CommandName() ) {
        my $obj = RPS::Statement::Mechanical::CA::BaseStatement->new( mechanicalStatementID => $logItem->CommandID() );
        $logItem->{CAMechanicalStatement} = $obj;
    } elsif ( 'RPS::Statement::Command::ShowLabel' eq $logItem->CommandName() ) {
        my $obj = RPS::Statement::Label::BaseStatement->new( labelRoyaltyStatementID => $logItem->CommandID() );
        $logItem->{LabelRoyaltyStatement} = $obj;
    } else {
        assert( 0, "unexpected command name: " . $logItem->CommandName() );
    }

    return $logItem;
}

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

    $args{command} = [
        'RPS::Statement::Command::ShowArtist',        'RPS::Statement::Command::ShowMechanical',
        'RPS::Statement::Command::ShowMechanicalPDF', 'RPS::Statement::Command::ShowUKMechanical',
        'RPS::Statement::Command::ShowCAMechanical',  'RPS::Statement::Command::ShowLabel'
    ];
    $args{most_recent} = 1;

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

}

1;

