use uuid::Uuid;
use crate::base::{input::Input, link::Link, output::Output};
use super::{BlockState, desc::BlockDesc};
pub trait BlockInput<R, W: Clone>: Input<Reader = R, Writer = W> {}
impl<R, W: Clone, T: ?Sized + Input<Reader = R, Writer = W>> BlockInput<R, W> for T {}
pub trait BlockOutput<W: Clone>: Output<Writer = W> {}
impl<W: Clone, T: ?Sized + Output<Writer = W>> BlockOutput<W> for T {}
pub trait BlockProps {
type Reader;
type Writer: Clone;
fn id(&self) -> &Uuid;
fn name(&self) -> &str;
fn desc(&self) -> &BlockDesc;
fn state(&self) -> BlockState;
fn set_state(&mut self, state: BlockState) -> BlockState;
fn inputs(&self) -> Vec<&(dyn BlockInput<Self::Reader, Self::Writer> + Send)>;
fn get_input(
&self,
name: &str,
) -> Option<&(dyn BlockInput<Self::Reader, Self::Writer> + Send)> {
self.inputs().iter().find(|i| i.name() == name).cloned()
}
fn get_input_mut(
&mut self,
name: &str,
) -> Option<&mut (dyn BlockInput<Self::Reader, Self::Writer> + Send)> {
self.inputs_mut().into_iter().find(|i| i.name() == name)
}
fn inputs_mut(&mut self) -> Vec<&mut (dyn BlockInput<Self::Reader, Self::Writer> + Send)>;
fn outputs(&self) -> Vec<&(dyn BlockOutput<Self::Writer> + Send)>;
fn get_output(&self, name: &str) -> Option<&(dyn BlockOutput<Self::Writer> + Send)> {
self.outputs().iter().find(|i| i.name() == name).cloned()
}
fn get_output_mut(
&mut self,
name: &str,
) -> Option<&mut (dyn BlockOutput<Self::Writer> + Send)> {
self.outputs_mut().into_iter().find(|i| i.name() == name)
}
fn outputs_mut(&mut self) -> Vec<&mut (dyn BlockOutput<Self::Writer> + Send)>;
fn links(&self) -> Vec<(&str, Vec<&(dyn crate::base::link::Link + Send)>)>;
fn remove_link(&mut self, link: &dyn Link) {
self.remove_link_by_id(link.id())
}
fn remove_link_by_id(&mut self, link_id: &Uuid);
fn remove_all_links(&mut self);
}