package BLAST::FileFactory;
BEGIN{ push(@INC, $ENV{LOCAL_PERL_MODULES}); }
use Carp;
use warnings;
use strict;
use BLAST::M0File;
use BLAST::M9File;
use BLAST::Config;


###################################################
sub new {
    my $pkg = shift;
    bless {
	config => BLAST::Config->new()
    }, $pkg;
}


###################################################
sub setConfig {
    my $self = shift;
    my $configFile = shift or croak "Config file name is not defined.";
    $self->getConfig()->parse($configFile);
}


###################################################
sub getConfig {
    my $self = shift;
    return $self->{config};
}


###################################################
sub getFileObject {
    my $self = shift;
    my $fileObj;
    if( $self->getFormatCode() == 0 ){
	$fileObj = BLAST::M0File->new();
    } elsif( $self->getFormatCode() == 8 ){
	$fileObj = BLAST::M9File->new();
    } elsif( $self->getFormatCode() == 9 ){
	$fileObj = BLAST::M9File->new();
    } else {
	croak "Invalid BLAST format code:" . $self->getFormatCode() . ".";
    }
    $fileObj->setFileName( $self->getBlastFileName() );
    return $fileObj;
}


###################################################
sub getFormatCode {
    my $self = shift;
    return $self->getConfig()->getFormatCode();
}


###################################################
sub getBlastFileName {
    my $self = shift;
    return $self->getConfig()->getOutputFile();
}

1;
