package APE::BarcodeFactory::PC_BarcodeFactory;

use base 'APE::BarcodeFactory';

use strict;
use warnings;

use APE::BarcodeFactory::ConcreteBarcode::DefaultBarcode;
use APE::BarcodeFactory::ConcreteBarcode::ColumnBarcode;
use APE::BarcodeFactory::ConcreteBarcode::SequenceBarcode;

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

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

	## Set this factories type.
	$args{'barcodeType'} = 'PC';

	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 = shift;

	my $processId = $self->getProcessId;

	## Create a SequenceBarcode - this object requires the sequence argument
	## so that it can create different formats for each of the sub processes.
	if($processId == 6615) {
	    return new APE::BarcodeFactory::ConcreteBarcode::SequenceBarcode
		(barcodeType     => $self->getBarcodeType,
		 flushController => $self->getFlushController,
		 entityId        => $self->getEntityId,
		 reservedData    => $self->getReservedData,
		 processId       => $processId,
		 sequence        => {6616=>"Plate A",6617=>"Plate B"});
	}
	
	## Create a ColumnBarcode Barcode object.
	elsif($processId == 5739) {
	    return new APE::BarcodeFactory::ConcreteBarcode::ColumnBarcode
		(barcodeType     => $self->getBarcodeType,
		 flushController => $self->getFlushController,
		 entityId        => $self->getEntityId,
		 reservedData    => $self->getReservedData,
		 processId       => $processId);
	}
	
	## Return the default Barcode object.
	else{
	    return new APE::BarcodeFactory::ConcreteBarcode::DefaultBarcode
		(barcodeType     => $self->getBarcodeType,
		 flushController => $self->getFlushController,
		 entityId        => $self->getEntityId,
		 reservedData    => $self->getReservedData,
		 processId       => $processId);
	}
    }
}

1;
