use std::str::FromStr;
use serde::{Serialize, Deserialize};

#[derive(Debug, Serialize, Deserialize)]
pub enum AbilityType {
  #[serde(rename = "strength")]
  Strength,
  #[serde(rename = "dexterity")]
  Dexterity,
  #[serde(rename = "constitution")]
  Constitution,
  #[serde(rename = "intelligence")]
  Intelligence,
  #[serde(rename = "wisdom")]
  Wisdom,
  #[serde(rename = "charisma")]
  Charisma
}

impl AbilityType {
  pub fn to_string(&self) -> String {
    match self {
      AbilityType::Strength => "Strength".to_string(),
      AbilityType::Dexterity => "Dexterity".to_string(),
      AbilityType::Constitution => "Constitution".to_string(),
      AbilityType::Intelligence => "Intelligence".to_string(),
      AbilityType::Wisdom => "Wisdom".to_string(),
      AbilityType::Charisma => "Charisma".to_string()
    }
  }
}

impl FromStr for AbilityType {
  type Err = ();
  fn from_str(s: &str) -> Result<Self, Self::Err> {
    match s {
      "Strength" => Ok(AbilityType::Strength),
      "Dexterity" => Ok(AbilityType::Dexterity),
      "Constitution" => Ok(AbilityType::Constitution),
      "Intelligence" => Ok(AbilityType::Intelligence),
      "Wisdom" => Ok(AbilityType::Wisdom),
      "Charisma" => Ok(AbilityType::Charisma),
      _ => Err(())
    }
  }
}