package APE::InputControllerFactory::ExoApeInputControllerFactory;

use base 'APE::InputControllerFactory';

$APE::InputControllerFactory::ExoApeInputControllerFactory::VERSION = '0.1';

use strict;
use warnings;

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

use APE::InputControllerFactory::ConcreteInputController::DefaultExoApeInputController;
use APE::InputControllerFactory::ConcreteInputController::COL2PLATE_InputController;
use APE::InputControllerFactory::ConcreteInputController::COORD2PLATE_InputController;
use APE::InputControllerFactory::ConcreteInputController::PC_InputController;
use APE::InputControllerFactory::ConcreteInputController::PRIMERCOUNT_InputController;
use APE::InputControllerFactory::ConcreteInputController::DTUNIQUEIND_InputController;
use APE::InputControllerFactory::ConcreteInputController::DNTODN_InputController;
use APE::InputControllerFactory::ConcreteInputController::CPPC_InputController;
use APE::InputControllerFactory::ConcreteInputController::CPEP_InputController;
use APE::InputControllerFactory::ConcreteInputController::DNIND_InputController;
use APE::InputControllerFactory::ConcreteInputController::COORDS2PLATE_InputController;


#use ExoSeq::APE::DnaCollection_IC;

{
    my %_attributes = ();

    my %object;

    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};
            }
        }

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

    #################################################################
    ## Implemented abstract method from base class. This method creates
    ## a description object depending on the process id and returns it.
    #################################################################
    sub getInstance {
        my ( $self, %args ) = @_;
        %args = $self->SUPER::validateInstanceRequest(%args);

        my $processId = delete $args{parentProcessId};

        my $ic;

        if ( $processId == 5643 ) {
            $ic = new
              APE::InputControllerFactory::ConcreteInputController::COORD2PLATE_InputController(
                %args);
        }

        elsif ( _isValidProcessCol2Plate($processId) ) {
            $ic = new
              APE::InputControllerFactory::ConcreteInputController::COL2PLATE_InputController(
                %args);
        }

        elsif ( $processId == 5740 ) {
            $ic = new
              APE::InputControllerFactory::ConcreteInputController::COL2PLATE_InputController(
                %args);
        }

        elsif ( $processId == 5672 || $processId == 6615 || $processId == 6685 )
        {
            $ic = new
              APE::InputControllerFactory::ConcreteInputController::PC_InputController(
                %args);
        }

        elsif ( $processId == 5644 || $processId == 5678 ) {
            $args{primerCount} = 1;
            $ic = new
              APE::InputControllerFactory::ConcreteInputController::PRIMERCOUNT_InputController(
                %args);
        }

        elsif ( $processId == 5675 ) {
            $ic = new
              APE::InputControllerFactory::ConcreteInputController::DTUNIQUEIND_InputController(
                %args);
        }

        elsif ( $processId == 6538 || $processId == 6623 ) {
            $ic = new
              APE::InputControllerFactory::ConcreteInputController::DNTODN_InputController(
                %args);
        }

        elsif ( $processId == 1 ) {
            $ic = new
              APE::InputControllerFactory::ConcreteInputController::CPPC_InputController(
                %args);
        }

        elsif ( $processId == 2 ) {
            $ic = new
              APE::InputControllerFactory::ConcreteInputController::CPEP_InputController(
                %args);
        }

        elsif ( $processId == 6659 ) {
            $ic =
              APE::InputControllerFactory::ConcreteInputController::PC_InputController
              ->new(%args);
        }

        elsif ( $processId == 6674 || $processId == 6680 ) {

            #$ic = ExoSeq::APE::DnaCollection_IC->new(%args);
            $ic =
              APE::InputControllerFactory::ConcreteInputController::DNTODN_InputController
              ->new(%args);
        }
        elsif ( $processId == 6833 ) {
            $ic =
              APE::InputControllerFactory::ConcreteInputController::DNTODN_InputController
              ->new(%args);
        }
		elsif ($processId == 6841) {
			$ic = APE::InputControllerFactory::ConcreteInputController::COORDS2PLATE_InputController
				->new(%args);
		}
        else {

            #$args{processId}   = $processId;
            #$args{description} = "Default InputController object";
            ## Grab a default InputController as the process id is not recognised.
            $ic = new
              APE::InputControllerFactory::ConcreteInputController::DefaultExoApeInputController(
                %args);

            #$ic =  $self->SUPER::getInstance(%args);
        }

        warn
          "*** '$self' returning InputController '$ic' for ppid '$processId'";
        return $ic;
    }

    ## Method to check if a process id should result in a col2plate
    ## InputController object being returned by the factory.
    sub _isValidProcessCol2Plate {
        my $processId = shift;
        foreach my $validProcessId ( 5739, 6543, 6236 ) {
            return TRUE if $processId == $validProcessId;
        }
        return FALSE;
    }

}

1;
