use std::ops::{Index, IndexMut};

use glc::{matrix::Angle, vector::Vector2f};
use serde::{Deserialize, Serialize};
use specs::{Component, VecStorage};

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Ship {
    pub type_: Type,
    pub agility: Angle<f32>,
    pub target_pos: Vector2f,
    pub target_dir: Vector2f,
}

#[derive(Clone, Debug, Default)]
pub struct Count {
    pub fighter: usize,
    pub bomber: usize,
    pub transporter: usize,
}

#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub enum Type {
    Fighter,
    Bomber,
    Transporter,
}

impl Component for Ship {
    type Storage = VecStorage<Self>;
}

impl Index<Type> for Count {
    type Output = usize;

    fn index(&self, index: Type) -> &Self::Output {
        match index {
            Type::Fighter => &self.fighter,
            Type::Bomber => &self.bomber,
            Type::Transporter => &self.transporter,
        }
    }
}

impl IndexMut<Type> for Count {
    fn index_mut(&mut self, index: Type) -> &mut Self::Output {
        match index {
            Type::Fighter => &mut self.fighter,
            Type::Bomber => &mut self.bomber,
            Type::Transporter => &mut self.transporter,
        }
    }
}
