#------------------------------------------------------------
# Copyright (C) 2011 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::Statement::Settings::ArtistSettingsHistory;

use strict;
use Carp;
use Data::Dumper;

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

use lib '/app/tools/rps/lib';
use RPS::DB::Item::ArtistRoyaltyStatementSettings;
use RPS::Statement::Settings::ArtistSettings;

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

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

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

    # We want to show the default settings, which all customers use initially.
    # I don't want to have to store that in the database, though.
    # So we'll tack it onto the list here - Essentially a 'virtual' record.
    #
    my $itemName = $self->_itemName();
    push @{ $self->{$itemName} }, RPS::Statement::Settings::ArtistSettings->new();

    # Now we'll interate over the list.   If there is more than one item, we want to
    # note the 'end date' as well as the 'create date'.  The 'end date' will be the same
    # as the next record's create date.
    # Sure, we could probably get the template do this...  maybe we should?
    # ... Well, frankly, it could get pretty weird in the template.  Let's just do it here.
    #
    my $lastDate;
    foreach my $settings ( @{ $self->{$itemName} } ) {
        $settings->{DateEnded} = Common::FormObject::Scalar::Date->new( value => $lastDate, readOnly => 1 );
        $lastDate = $settings->{DateCreated}->_getValue();
    }

    # Add pagination information
    #
    $self->{Pagination}->{TotalCount} = ( scalar @{ $self->{$itemName} } );

    if ( $args{id} ) {
        $self->{Pagination}->{CurrentPage} = $args{id};
    } else {
        $self->{Pagination}->{CurrentPage} = 0;
    }

    return $self;
}

sub _itemName { return 'ArtistStatementSetting'; }

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

    my $c = RPS::DB::Item::ArtistRoyaltyStatementSettings->GetAllOrderedByDate();

    return $c;
}

sub _getObj {
    my ( $self, $dbItem ) = @_;
    return RPS::Statement::Settings::ArtistSettings->new( _dbItem => $dbItem );
}

###
1;    #
###
