package SingleDance;

# sub new {
#   my $proto=shift;
#   my $class=ref($proto) || $proto;
#   my $self={};
#   my($level, $continent, $name, $abbrev, $style, $dance_abbrev)=@_;
# 
#   $self->{LEVEL}=$level;
#   $self->{CONTINENT}=$continent;
# #  $self->{CONSTANTS_NAME}=$name;
# # Not having this is bad.  Who uses new, anyways?
#   $self->{NAME}=$name;
#   $self->{ABBREV}=$abbrev;
#   $self->{STYLE}=$style;
#   $self->{DANCE_ABBREV}=$dance_abbrev;
#   $self->{NUM_DANCES}=1;
# 
#   bless($self, $class);
#   return($self);
# }

# This constructor should only be used by Constants to construct Master.
# This way, the server god only needs to enter a minimal of information
# (thereby lessening the likelihood of error).  All other code should
# optimize by using the full constructor (the calls to Constants.get*
# are these heinous if constructs.

sub new {
  my $proto=shift;
  my $class=ref($proto) || $proto;
  my $self={};
  my($level, $continent, $name)=@_;

  $self->{NUM_DANCES}=1;
  if ($continent eq INTERNATIONAL) {
    $self->{LEVEL}=$level;
    $self->{CONTINENT}=$continent;
    $self->{CONSTANTS_NAME}=$name;
    $self->{NAME}=Constants::get($name);
    $self->{ABBREV}=Constants::getLevelAbbrev($level).Constants::get(DELIM). 
      Constants::get(INTERNATIONAL_ABBREV).Constants::get(DELIM). 
	Constants::getDanceAbbrev($name);
    $self->{STYLE}=Constants::getStyle($name, $level);
    $self->{DANCE_ABBREV}=Constants::getDanceAbbrev($name);
  } elsif ($continent eq AMERICAN) {
    $self->{LEVEL}=$level;
    $self->{CONTINENT}=$continent;
    $self->{CONSTANTS_NAME}=$name;
    $self->{NAME}=Constants::get($name);
    $self->{ABBREV}=Constants::getLevelAbbrev($level).Constants::get(DELIM). 
      Constants::get(AMERICAN_ABBREV).Constants::get(DELIM). 
	Constants::getDanceAbbrev($name);
    $self->{STYLE}=Constants::getStyle($name, $level);
    $self->{DANCE_ABBREV}=Constants::getDanceAbbrev($name);
  } else {
    # FUN_DANCE, both we don't explicitly check for it, although we do
    # explictly replace it.
    $self->{LEVEL}=$level;
    $self->{CONTINENT}=Constants::get(FUN_DANCE);
    $self->{CONSTANTS_NAME}=$name;
    $self->{NAME}=$name;
    $self->{ABBREV}=Constants::getDanceAbbrev($name);
    $self->{STYLE}=Constants::getStyle($name, $level);
    $self->{DANCE_ABBREV}=Constants::getDanceAbbrev($name);
  }

  $self->{FAST_COMPARE}=$self->{ABBREV};
  bless($self, $class);
  return($self);
}
 
sub newFromDB {
  my $proto=shift;
  my $class=ref($proto) || $proto;
  my $IN=$_[0];
  my $self={};
  my ($level, $continent, $name);
  
  $level=<$IN>;  chop($level);
  $continent=<$IN>;  chop($continent);
  $name=<$IN>;  chop($name);

#  $level=shift(@$IN);  chop($level);
#  $continent=shift(@$IN);  chop($continent);
#  $name=shift(@$IN);  chop($name);

  return(SingleDance->new($level, $continent, $name));
}

sub equals {
  my ($self, $doppel)=@_;
  if (($self->{LEVEL} eq $doppel->{LEVEL}) and
      ($self->{CONTINENT} eq $doppel->{CONTINENT}) and
      ($self->{CONSTANTS_NAME} eq $doppel->{CONSTANTS_NAME})) {
    return(1);
  }
  return(0);
}

sub getAbbrev {
  my $self=shift;
  return($self->{ABBREV});
}

sub getContinent {
  my $self=shift;
  return($self->{CONTINENT});
}

sub getDanceAbbrev {
  my $self=shift;
  return($self->{DANCE_ABBREV});
}

sub getLevel {
  my $self=shift;
  return($self->{LEVEL});
}

#   // We do it here, because in general, we'll so very rarely need to do this
#   // kind of grovelling.  So pay it each time we have to.
sub getLevelExp {
  my $self=shift;
  my $level=$self->{LEVEL};

  if ($level eq NEWCOMER) {
    return(Constants::get(NEWCOMER_EXP));
  } elsif ($level eq BEGINNER) {
    return(Constants::get(BEGINNER_EXP));
  } elsif ($level eq INTERMEDIATE) {
    return(Constants::get(INTERMEDIATE_EXP));
  } elsif ($level eq ADVANCED) {
    return(Constants::get(ADVANCED_EXP));
  } elsif ($level eq OPEN) {
    return(Constants::get(OPEN_EXP));
  } elsif ($level eq PRE_BRONZE) {
    return(Constants::get(PRE_BRONZE_EXP));
  } elsif ($level eq BRONZE) {
    return(Constants::get(BRONZE_EXP));
  } elsif ($level eq SILVER) {
    return(Constants::get(SILVER_EXP));
  } elsif ($level eq GOLD) {
    return(Constants::get(GOLD_EXP));
  } elsif ($level eq NOVICE) {
    return(Constants::get(NOVICE_EXP));
  } elsif ($level eq PRE_CHAMP) {
    return(Constants::get(PRE_CHAMP_EXP));
  } elsif ($level eq CHAMP) {
    return(Constants::get(CHAMP_EXP));
  } elsif ($level eq TEAMMATCH) {
    return(Constants::get(TEAMMATCH_EXP));
  } else {
    Error::Croak("Unexpected level in SingleDance::getLevelExp(): '$level'");
  }
}

sub getConstantsName {
  my $self=shift;
  return($self->{CONSTANTS_NAME});
}

sub getCanonicalFullName {
  my $self=shift;
  if ($self==0) {
    return;
  } else {
    return($self->{LEVEL}." ".$self->{CONTINENT}." ".$self->{NAME});
  }
}

sub getFullName {
  my $self=shift;
  if ($self==0) {
    return;
  } else {
    return(Constants::get($self->{LEVEL})." ".
	   Constants::get($self->{CONTINENT})." ".$self->{NAME});
  }
}

sub getName {
  my $self=shift;
  if ($self==0) {
    return;
  } else {
    return($self->{NAME});
  }
}

sub getNumDances {
  return(1);
}

sub getStyle {
  my $self=shift;
  return($self->{STYLE});
}

sub getStyle2 {
  my $self=shift;
  my $style=$self->{STYLE};
  my $continent=$self->{CONTINENT};
  if (($style eq ESQUE) && ($continent eq INTERNATIONAL)) {
    return(Constants::get(LATIN));
  } elsif (($style eq ESQUE) && ($continent eq AMERICAN)) {
    return(Constants::get(RHYTHM));
  } elsif (($style eq MODERN) && ($continent eq INTERNATIONAL)) {
    return(Constants::get(STANDARD));
  } elsif (($style eq MODERN) && ($continent eq AMERICAN)) {
    return(Constants::get(SMOOTH));
  } else {
    return(Constants::get(OTHER));
  }
}

sub write {
  my $self=shift;
  my $LOG=$_[0];
  $numDances=$self->getNumDances();
  print $LOG "$numDances\n";
  print $LOG $self->getLevel()."\n";
  print $LOG $self->getContinent()."\n";
  print $LOG $self->getConstantsName()."\n";
}

1;
