use bladeink::story::Story;

use crate::entity::EntityHandle;

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum ParryButton
{
    I,
    J,
    L,
}

impl ParryButton
{
    pub fn from_tag(tag: &str) -> Option<Self>
    {
        match tag.trim().to_lowercase().as_str()
        {
            "i" => Some(ParryButton::I),
            "j" => Some(ParryButton::J),
            "l" => Some(ParryButton::L),
            _ => None,
        }
    }
}

pub enum DialogPhase
{
    Displaying
    {
        timer: f32
    },
    ProjectileInFlight
    {
        projectile_entity: EntityHandle
    },
}

pub struct DialogBubbleComponent
{
    pub story: Story,
    pub character_entity: EntityHandle,
    pub current_text: String,
    pub phase: DialogPhase,
    pub correct_parry: Option<ParryButton>,
    pub display_time: f32,
}

pub struct DialogSourceComponent
{
    pub ink_json: String,
}

pub struct DialogProjectileComponent
{
    pub bubble_entity: EntityHandle,
    pub correct_parry: ParryButton,
    pub parry_window_open: bool,
}

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum DialogOutcome
{
    Hit,
    Evaded,
    WrongParry,
    ParriedI,
    ParriedJ,
    ParriedL,
}

impl DialogOutcome
{
    pub fn to_choice_tag(&self) -> &'static str
    {
        match self
        {
            DialogOutcome::Hit => "hit",
            DialogOutcome::Evaded => "evaded",
            DialogOutcome::WrongParry => "wrong_parry",
            DialogOutcome::ParriedI => "parried_i",
            DialogOutcome::ParriedJ => "parried_j",
            DialogOutcome::ParriedL => "parried_l",
        }
    }
}

pub struct DialogOutcomeEvent
{
    pub bubble_entity: EntityHandle,
    pub outcome: DialogOutcome,
}
