#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2010 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#---------------------------------------------------------------
package BookPub::Catalog::Import::Status::WithFileLists;
use strict;
use warnings;

use lib '/app/tools/common/lib';
use lib '/app/tools/bookpub/lib';
use BookPub::DB::Item::CatalogImport;
use Common::RSApp;
use Common::Util;
use Common::Assert;
use Common::FormObject;
use BookPub::DB::Item::CatalogImportItem::File;
use BookPub::DB::Item::CatalogImportItem::FTPFile;

use base 'BookPub::Catalog::Import::Status';

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

    $self->SUPER::_initProperties($props);

    my $catalogImportID = $props->{catalog_import_id};
    if ($catalogImportID) {
        $self->{FTPFile} = [];
        $self->{File}    = [];
        my @ftpFiles;
        my @files;
        my $ftpFileCollection = BookPub::DB::Item::CatalogImportItem::FTPFile->GetAllByCatalogImport($catalogImportID);
        while ( my $ftpFile = $ftpFileCollection->next() ) {
            push @ftpFiles, { FileName => $ftpFile->file_name() };
        }

        my $fileCollection = BookPub::DB::Item::CatalogImportItem::File->GetAllByCatalogImport($catalogImportID);
        while ( my $file = $fileCollection->next() ) {

            # I don't want to display the entire path...
            #
            my $filePath = $file->file_path();
            my @pathBits = split( /\//, $filePath );
            my $fileName = pop @pathBits;
            push @files, { FileName => $fileName };
        }

        $self->{FTPFileList}{File} = \@ftpFiles;
        $self->{FileList}{File}    = \@files;
    }
}

###
1;    #
###
