pub mod circle_element;
pub mod line_element;
pub mod rectangle_element;

pub use circle_element::CircleElement;
pub use line_element::LineElement;
use mlua::{FromLua, Lua, UserData, UserDataMethods};
pub use rectangle_element::RectangleElement;

#[derive(Debug, Clone)]
pub struct Drawable {
    pub element: Element,
    pub layer: usize,
}

impl Drawable {
    pub fn new(element: Element, layer: usize) -> Self {
        Drawable { element, layer }
    }
}

#[derive(Debug, Clone, PartialEq, Copy)]
pub enum Element {
    Line(LineElement),
    Rectangle(RectangleElement),
    Circle(CircleElement),
}

impl FromLua for Element {
    fn from_lua(value: mlua::Value, _: &Lua) -> mlua::Result<Self> {
        match value {
            mlua::Value::UserData(ud) => Ok(*ud.borrow::<Self>()?),
            _ => unreachable!(),
        }
    }
}

impl UserData for Element {
    fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {}
}
