package Report::Dynamic::ReportList;

use strict;
use warnings;
use Data::Dumper;

use lib '/app/tools/rps/lib';
use RPS::Report::Dynamic::Factory;

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

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

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

    my $accessLevel = $args{accessLevel};
    $accessLevel = 1 unless $accessLevel;

    $self->{Report} = [];

    my $collection =
      $args{active}
      ? Report::DB::Item::Report->GetAllActive()
      : Report::DB::Item::Report->GetAll();

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

            # Check access level!
            #
            if ( $report->UserLevelIsValid($accessLevel) ) {
                push @{ $self->{Report} }, $report;
            }
        }
    }

    return $self;
}

sub _reportObject {
    my $self = shift;
    my $dbitem = shift || die;
    return RPS::Report::Dynamic::Factory->Fetch( $dbitem->report_id );
}

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

    return $self->{Report};
}

###
1;    #
###
