package APE::InputControllerFactory::ConcreteInputController::DNTODN_InputController;

use base 'APE::InputControllerFactory::ConcreteInputController::DefaultExoApeInputController';

$APE::InputControllerFactory::ConcreteInputController::DNTODN_InputController::VERSION = '1.1';

use strict;
use warnings;
use Carp;

use APE::InputControllerFactory::Plugin::UniqueRequirementCreator;

use constant LOGIN => 'snp';

use constant TRUE  => 1;
use constant FALSE => 0;

{
    my %_attributes = ( );

    my %object;

    ## Autoloader wannabe. Inserts the sub calls that I want to be
    ## accessible into the symbol table.
    foreach my $attName (keys(%_attributes)) {
	no strict 'refs';
	*{__PACKAGE__ . "::get\u$attName"} = sub { $object{ $_[0] }->{$attName} }
    }


    #################################################################
    ## Initialise the objects private attributes. The argument is
    ## deleted as it is found, initialised and set.
    #################################################################
    sub _init {
	my ($self,%args) = @_;

	foreach my $attName (keys(%args)) {
	    if(exists($_attributes{$attName})) {
		$object{ $self }->{$attName} = delete $args{$attName};
	    }
	}

  	## Set the description as this is a specialised InputController.
	$args{description} = "An InputController that gathers data for ".
	  "a copy between two or more DNA plates entities."
	    unless $args{description};

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


=item $ic->createRequirements()

Creates the Requirement objects based on the arraying process. This
method uses the
APE::InputControllerFactory::Plugin::UniqueRequirementCreator plugin
class to create Requirement objects to represent the unique input
entities for the arraying process. For instance, if an arraying
process requires two input entities, and their APE::AtomicProcess
objects have the same inConcreteEntity number i.e. they are the same
entity, then this plugin will create a single Requirement object to
request the entity - see
APE::InputControllerFactory::Plugin::UniqueRequirementCreator plugin
class.

=cut

    sub createRequirements {
	my $self = shift;
	my $option = APE::InputControllerFactory::Plugin::UniqueRequirementCreator->new
	  (controller => $self);
	$option->run();
    }

=item $ic->getData(Requirement)

Calls the base classes getData() method. The base class completes a
database lookup using the DN plate id number.

This method swaps the data held in the 4th (array index:3) element
(id_dnawell) with the data held in the 6th (array index:5)
element. This means that the DN_FlushController will replicate the
contents of the source wells into the new DNA plate instead of
pointing each of the new wells back to the source DNA plates wells.

XXX Get rid of indexes.

=cut

    sub getData {
	my ($self,$requirement) = @_;
	$self->SUPER::getData($requirement);
	my $dataStore = $requirement->getDataStore();
	## Change the content type (dna_well.id_content_type) to be an
	## id_dnawell (14).
	my @alteredDataStore=();
	foreach my $well (@$dataStore) {
#	    $well->[4] = 14;
	    my $temp   = $well->[3]; ## id_dnawell
	    $well->[3] = $well->[5]; ## Switch id_dnawell with id_content
	    $well->[5] = $temp;      ## Switch id_content to be id_dnawell
	}
    }


=item DESTORY

Destructor method. Cleans up when the object is deleted. Calls
$self->SUPER::DESTROY to ensure that the base class gets a chance to
clean up.

=cut

    sub DESTROY {
	my $self = shift;
	delete $object{$self};
	$self->SUPER::DESTROY;
    }
}

1;

