#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2010 RoyaltyShare, Inc.   All Rights Reserved
#---------------------------------------------------------------

package BookPub::Catalog::Import::Parser::Factory;
use strict;
use warnings;

use File::Path;
use Data::Dumper;

use lib '/app/tools/common/lib';
use lib '/app/tools/bookpub/lib';
use lib '/app/tools/data_classes/lib';
use Common::Assert;
use Common::RSApp;

use BookPub::DB::Item::CatalogImportItem::File;
use BookPub::Catalog::Import::Parser::ONIX;
use BookPub::Catalog::Import::Parser::FlatFile::HayHouseAudio;
use BookPub::Catalog::Import::Parser::FlatFile::RSStandard;

# This factory will return the correct Parser object based on the file's type.
# (... and possible client_id. Might as well leave that possibility in play).

my %gPackageMap = (
    BookPub::DB::Item::CatalogImportItem::File::kFileTypeONIX()          => 'BookPub::Catalog::Import::Parser::ONIX',
    BookPub::DB::Item::CatalogImportItem::File::kFileTypeHayHouseAudio() => 'BookPub::Catalog::Import::Parser::FlatFile::HayHouseAudio',
    BookPub::DB::Item::CatalogImportItem::File::kFileTypeRSStandard()    => 'BookPub::Catalog::Import::Parser::FlatFile::RSStandard',
);

sub NewParser {
    my ( $class, %args ) = @_;

    my $type = $args{type};
    assert($type);

    my $pkg = $gPackageMap{$type};
    assert( $pkg, "ERROR - no Parser can be found for file type '$type'" );

    return $pkg->new(%args);
}

1;
