use std::fmt;

use serde::{Deserialize, Serialize};

use crate::messages::std::PowerSignalCabin;

#[derive(Default, Debug, Hash, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum CockpitSide {
    #[default]
    A,
    B,
}

impl CockpitSide {
    pub fn to_mul(&self) -> f32 {
        match &self {
            CockpitSide::A => 1.0,
            CockpitSide::B => -1.0,
        }
    }
}

impl fmt::Display for CockpitSide {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            CockpitSide::A => write!(f, "0"),
            CockpitSide::B => write!(f, "1"),
        }
    }
}

impl From<CockpitSide> for PowerSignalCabin {
    fn from(value: CockpitSide) -> PowerSignalCabin {
        match value {
            CockpitSide::A => PowerSignalCabin::A,
            CockpitSide::B => PowerSignalCabin::B,
        }
    }
}

impl From<CockpitSide> for String {
    fn from(value: CockpitSide) -> String {
        match value {
            CockpitSide::A => "A".to_string(),
            CockpitSide::B => "B".to_string(),
        }
    }
}

impl From<CockpitSide> for usize {
    fn from(value: CockpitSide) -> Self {
        value as usize
    }
}

impl From<CockpitSide> for u8 {
    fn from(value: CockpitSide) -> Self {
        value as u8
    }
}

#[derive(Debug, Copy, Clone, PartialEq, Default)]
pub enum TractionDirection {
    Forward,
    #[default]
    Neutral,
    Backward,
}
