package Stats::Redshift::DatabaseList;

use strict;
use warnings;
use open ':std', ':encoding(UTF-8)';

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

use base 'Class::Accessor';

__PACKAGE__->mk_accessors(qw/rps dtmv/);

sub new {
    my $class = shift;
    my $self  = {};
    bless $self, $class;
    $self->_init;
    $self;
}

sub _init {
    my $self = shift;
    my $dbx  = Common::Session::getdbx('admindb');
    foreach my $type ( qw/rps dtmv/ ) {
        my $search = { 'client_type' => $type, 'calc_stat' => 1 };
        my $rset   = $dbx->resultset('Report::DDb')->search( $search, { 'order_by' => 'db_name' } );

        my $allclients;
        while ( my $row = $rset->next ) {
            push @{$allclients}, $row;
        }
        if ( $type eq 'rps' ) {
            $self->rps($allclients);
        } else {
            $self->dtmv($allclients);
        }
    }
    $dbx->getdbh->disconnect;
}

1;
