package Couple;

# Couples consist of two Competitors: one is a Leader and one is a
# Follower.  Note that Michael dancing with Reena is distinct from
# Reena dancing with Michael.

sub new {
  my $proto=shift;
  my $class=ref($proto) || $proto;
  my $self={};

  my ($leader, $follower)=@_;

  $self->{LEADER}=$leader;
  $self->{FOLLOWER}=$follower;
# This is probably obsolete.
  $self->{FAST_COMPARE}=$leader->getLName().$follower->getLName();
  bless($self, $class);
  return($self);
}

sub newFromDB {
  my $proto=shift;
  my $class=ref($proto) || $proto;
  my $IN=$_[0];
  my ($self, $leader, $follower);

  $leader=Competitor->newFromDB($IN);
  $follower=Competitor->newFromDB($IN);

  $self->{LEADER}=$leader;
  $self->{FOLLOWER}=$follower;
  $self->{FAST_COMPARE}=$leader->getLName().$follower->getLName();
  bless($self, $class);

  return($self);
}

# Is the passed-in Competitor a member of this Couple?
sub contains {
  my $self=shift;
  my $comp=$_[0];

  return ((Competitor::equals($self->{LEADER}, $comp)) or
	  (Competitor::equals($self->{FOLLOWER}, $comp)));
}

# Returns true if a member of the passed-in Couple is in this Couple.
# E.g., returns 1 when comparing Michael & Reena with Bill & Micheal.
sub containsCouple {
  my $self=shift;
  my $coup=$_[0];

  if (Competitor::equals($self->{LEADER}, $coup->{LEADER}) ||
    Competitor::equals($self->{LEADER}, $coup->{FOLLOWER}) ||
    Competitor::equals($self->{FOLLOWER}, $coup->{LEADER}) ||
    Competitor::equals($self->{FOLLOWER}, $coup->{FOLLOWER})) {
      return(1);
  }
  return (0);
}

sub equals {
  my $self=shift;
  my $coup=$_[0];

  if (Competitor::equals($self->{LEADER}, $coup->{LEADER}) and
      Competitor::equals($self->{FOLLOWER}, $coup->{FOLLOWER})) {
    return(1);
  }
  return(0);
}

sub getFollower {
  my $self=shift;
  return($self->{FOLLOWER});
}

sub getLeader {
  my $self=shift;
  return($self->{LEADER});
}

sub getNames {
  my $self=shift;

  return($self->{LEADER}->getName()." ".
	 Constants::get(HTML_MSG10)." ".$self->{FOLLOWER}->getName());
}

sub write {
  my $self=shift;
  my $LOG=$_[0];

  $self->{LEADER}->write($LOG);
  $self->{FOLLOWER}->write($LOG);
}

1;

