package User::Team::Role;

use strict;
use warnings;

=head1 NAME

User::Team::Role - A class that represents a users role within a team
within the tracking database (part of the User library).

=head1 SYNOPSIS

See User class and the 'SEE ALSO' section for details on how to use
the User library.

A User::Team::Role object can be created as a place holder.

use User::Team::Role;

my $role = new User::Team::Role(roleId => 16344, roleType => 'Chimp');

print "Role RoleId:   ", $role->getRoleId(), "\n";
print "Role RoleType: ", $role->getRoleType(), "\n";


=head1 DESCRIPTION

This class represents a database users role within a team. This class
is part of the User library.

=head1 CONSTANTS

=over 10

=item TRUE

Boolean true.

=cut

use constant TRUE  => 1;

=item FALSE

Boolean false.

=back

=cut

use constant FALSE => 0;


=head1 CONSTRUCTOR

The following arguments may be passed to the constructor during
instantiation.

=over 10

=item roleId

Required. A role id (ID_ROLE.TEAM_PERSON_ROLE@CAS).

=item roleType

Required. A role type name (ROLE_TYPE.TEAM_PERSON_ROLE@CAS).

=back

=head1 METHODS

=over 10

=cut


{
    my %_attributes = (
		       roleId   => undef,
		       roleType => undef,
		       );

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


=item User::Team::Role->new(arg => value,... => ?);

This is the constructor for the User::Team::Role class (see the
CONSTRUCTOR section for more information on valid arguments). This
method calls the _init(%args) method which allows deriving classes
access to the argument list passed to the constructor (see
User::Team::Role::_init(%args) method). An error is thrown if there
are still arguments left in the %args hash after the _init() method
has been called.

=cut

    sub new {
	my ($proto,%args) = @_;
	my $class = ref($proto) || $proto;
	my $self  = bless {}, $class;
	%args = $self->_init(%args);
	my @leftover = keys %args;
	die "Error: the following arguments are unknown - @leftover\n" 
	  if @leftover;
	return $self;
    }


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

Private method. Documented to aid sub classing. Derived classes should
implement their own _init() methods that removes the arguments they
are interested in from the passed %args hash. The %args hash should be
returned from _init() to populate the base class:

Derived class:

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

This method checks that the required teamName argument has been passed
and dies if it has not.

If the default flag has been set to true then this method calls the
findDefaultBarcodePrinter() and findDefaultLinePrinter() methods to
find the default teams barcode and line printers (see
findDefaultBarcodePrinter() and findDefaultLinePrinter() methods).

=cut

    sub _init {
	my ($self,%args) = @_;
	foreach my $attName (keys(%args)) {
	    if(exists($_attributes{$attName})) {
		$object{ $self }->{$attName} = delete $args{$attName};
	    }
	}
	## Argument roleId is required.
	die "ERROR: argument 'roleId' is required."
	  unless $object{ $self }->{roleId};
	## Argument roleType is required.
	die "ERROR: argument 'roleType' is required."
	  unless $object{ $self }->{roleType};

	return %args;
    }

=item DESTROY

Destructor method.

=cut

    sub DESTROY {
	my $self = shift;
	delete $object{ $self };
    }
}

1;

=back

=head1 SEE ALSO

User User::Team User::Printer User::Printer::BarcodePrinter

=head1 AUTHOR

Simon Holroyd <holroyd@sanger.ac.uk>
7th March 2005

=cut


