package ExoSeq::APE::DnaCollection_FCF;

$ExoSeq::APE::DnaCollection_FCF::VERSION = '0.1';

use base qw(APE::FlushControllerFactory::ExoApeFlushControllerFactory);
use strict;
use warnings;

use ExoSeq::APE::DnaCollection_FC;

=head1 NAME

ExoSeq::APE::DnaCollection_FCF - Application specific fluch controller
factory class for the DNA Collection project.


=head1 SYNOPSIS

use ExoSeq::APE::DnaCollection_FCF
use User;

my $user = User->new(personId => 137);

my $object = ExoSeq::APE::DnaCollection_FCF->new
  (userObj => \$user);

my $concreteFc = $object->getInstance
  (arrayingEntity => APE::ArrayingEntity->new());

=head1 DESCRIPTION

A flush controller factory for the ExoSeq DNA Collection project. This
flush controller factory returns an ExoSeq::APE::DnaCollection_FC
object for 'DN' requests from process XXX.

=head1 CONSTANTS

=over 5

=item TRUE

This is a boolean true constant.

=cut

use constant TRUE  => 1;


=item FALSE

This is a boolean false constant.

=cut

use constant FALSE => 0;


=back

=head1 CONSTRUCTOR

=over 5

=item $object = ExoSeq::APE::DnaCollection_FCF->new(option => value,...?);

The following arguments may be passed to the constructor so are
options for all derived classes of type Entity.

=over 5

=item example

Required. An example option.

=back

=cut

my %_attributes = ();


=head2 INSTANTIATION PROCESS

The new method for this object calls the _init() method on $self. If
$self is a derived class then it's _init() method will be called
giving it the chance to remove any arguments it requires from the
%args hash. If there is no _init() method in the derived class then
the _init() method in this class is called.

Derived classes implementing a _init() method should return the %args
hash to the base class:

package Derived::Class;

sub _init {
   my ($self,%args) = @_;
   my $argument = delete $args{classArgument};
   return $self->SUPER::_init(%args);
}

=cut


=head1 METHODS

=over 10

=item $plate->_init(%args);

Private method. This method is called by the new method during object
instantiation (see the INSTANTIATION process). The method removes any
of the arguments required by the object from the %args hash and
returns it.

See the INSTANTIATION section for information on how to use this
method in a derived class.

=cut

sub _init {
    my ($self,%args) = @_;
    foreach my $arg (keys(%args)) {
	$self->{"_".$arg} = delete $args{$arg}
	  if exists $_attributes{$arg};
    }

    ## Check for required attributes.
    foreach my $requiredArg (qw//) {
	die "Error: argument '$requiredArg' is required"
	  unless $self->{"_".$requiredArg};
    }

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


foreach my $attName (keys(%_attributes)) {
    no strict 'refs';
    *{__PACKAGE__ . "::get\u$attName"} = sub { $_[0]->{"_".$attName} }
}


=item $object->getInstance()

Overrides the base classes getInstance() method to service requests
for type 'DN' concrete fluch controller from process id XXX. Passes
all other requests to the base class and returns the resulting
concrete flush controller.

=cut

sub getInstance {
    my ($self,%args) = @_;
    %args = $self->SUPER::validateInstanceRequest(%args);
    my $arrayingEntity = $args{arrayingEntity};
    my $processId      = $arrayingEntity->getParentProcessId();
    my $prefix         = $arrayingEntity->getOutPrefix();
    my $fc;
    if($prefix eq 'DN' && $processId == 6674) {
	$args{userObj} = $self->getUserObj();
	$fc = ExoSeq::APE::DnaCollection_FC->new(%args);
    }else{
	$fc = $self->SUPER::getInstance(%args);
    }
    return $fc;
}

1;

=back

=head1 ALSO SEE

APE::FlushControllerFactory::ExoApeFlushControllerFactory,
ExoSeq::APE::DnaCollection_FC

=head1 AUTHOR

Simon Holroyd <holroyd@sanger.ac.uk>

=cut
