use serde::Deserialize;

use crate::common::direction::Direction;

use super::{board::Board, board_position::BoardPosition};

#[derive(Debug, Deserialize, PartialEq, Eq)]
pub enum AbilityType {
	Start,
	Checkpoint,
	Secret,
	Stat,
	Spirit,
	Support,
	Attack,
	Magic,
	Reprisal,
	Defense,
}

#[derive(Debug, Deserialize, PartialEq, Eq)]
pub struct Ability {
	pub name: String,
	#[serde(deserialize_with = "crate::ddd::board_position::deserialize_position")]
	pub pos: BoardPosition,
	pub r#type: AbilityType,
	pub price: String,
	pub route: Option<u32>,
	pub path: Vec<Direction>,
	pub tip: Option<String>,
}

impl Ability {
	pub fn tip(&self) -> String {
		self.tip.clone().unwrap_or_default()
	}

	pub fn get_slot_details(&self, board: &Board) -> String {
		let mut details = String::new();
		if let Some(route) = self.route {
			for broute in &board.routes {
				if broute.id == route {
					details += &format!("{} ", broute.color);
					break;
				}
			}
		}

		for path in &self.path {
			match path {
				Direction::North => details += "north ",
				Direction::South => details += "south ",
				Direction::East => details += "east ",
				Direction::West => details += "west ",
			}
		}

		if self.r#type == AbilityType::Start {
			details += "start ";
		}

		details
	}
}
