package Contact;

# constructor
sub new {
   my $class = shift;
   my $self = {
      "first_name" => "ANONYMOUS",
      "middle_name" => '',
      "last_name" => "ANONYMOUS",
      "street1" => '',
      "street2" => '',
      "city" => '',
      "state" => '',
      "zip" => '',
      "country" => '',
      "email_addr" => '',
      "mobile" => '',
      "home_phone" => ''
    };
    bless $self, $class;
    my($f, $m, $l) = @_;
    if ($f =~ /^[a-zA-Z]+.*/) {$self->{"first_name"} = $f;}
    if ($m =~ /^[a-zA-Z]+.*/) {$self->{"middle_name"} = $m;}
    if ($l =~ /^[a-zA-Z]+.*/) {$self->{"last_name"} = $l;}
    return $self;
}

sub getKey {
   my $self = shift;
   return $self->getLastName() .
          $self->getFirstName() .
          $self->getMiddleName();
}

sub getFirstName {my $self = shift; $self->{"first_name"};}

sub getMiddleName {my $self = shift; $self->{"middle_name"};}

sub getLastName {my $self = shift; $self->{"last_name"};}

sub getAllInfo {
   my $self = shift;
   push my @info,
   $self->{"first_name"},
   $self->{"middle_name"},
   $self->{"last_name"},
   $self->{"street1"},
   $self->{"street2"},
   $self->{"city"},
   $self->{"state"},
   $self->{"zip"},
   $self->{"country"},
   $self->{"email_addr"},
   $self->{"mobile"},
   $self->{"home_phone"};
   return @info;
}

sub setFirstName {
    my $self = shift;
    my $new = shift;
    if ($new =~ /^[a-zA-Z]+.*/) {$self->{"first_name"} = $new;}
}

sub setMiddleName {
    my $self = shift;
    my $new = shift;
    $self->{"middle_name"} = $new;
}

sub setLastName {
    my $self = shift;
    my $new = shift;
    if ($new =~ /^[a-zA-Z]+.*/) {$self->{"last_name"} = $new;}
}

sub setAllInfo {
   my $self = shift;
   $self->{"first_name"} = shift;
   $self->{"middle_name"} = shift;
   $self->{"last_name"} = shift;
   $self->{"street1"} = shift;
   $self->{"street2"} = shift;
   $self->{"city"} = shift;
   $self->{"state"} = shift;
   $self->{"zip"} = shift;
   $self->{"country"} = shift;
   $self->{"email_addr"} = shift;
   $self->{"mobile"} = shift;
   $self->{"home_phone"} = shift;
}

sub toString {
   my $self = shift;
   my $l = $self->{"last_name"};
   my $f = $self->{"first_name"};
   my $m = $self->{"middle_name"};
   my $n = "$l, $f";
   if ($m) {$n .= " $m";}
   return $n;
}

# Every module should return 1 (true) if it loads successfully.
1;
