#include <iostream>
#include "Card.h"

const static char suitLabel[] = {'C', 'D', 'H', 'S'};
const static char valueLabel[] = {'?', 'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'};


char* Card::suitName(Suit s) {
  static char* names[] = {"Clubs", "Diamonds", "Hearts", "Spades"};
  return names[s];
}

char Card::toChar(Suit s) {
  char result = '?';
  int i = s;
  if ((i>=0) && (i<=3))
    result = suitLabel[i];
  return result;
}

char Card::toChar(Value v) {
  char result = '?';
  int i = v;
  if ((i>=1) && (i<=13))
    result = valueLabel[i];
  return result;
}


Card::Suit Card::toSuit(char key) {
  Card::Suit result = NOSUIT;
  for (int j=0; j<4; j++)
    if (key == suitLabel[j]) result = (Suit) j;
  return result;
}


Card::Value Card::toValue(char key) {
  Card::Value result = NOVALUE;
  for (int j=1; j<=13; j++)
    if (key == valueLabel[j]) result = (Value) j;
  return result;
}





/*
 * print card information
 */
std::ostream& operator<<(std::ostream& out, const Card& c) {
  out << ((c.value==Card::NOVALUE) ? '?' : Card::toChar(c.value));
  out << ((c.suit==Card::NOSUIT)   ? '?' : Card::toChar(c.suit));
  return out;
}
