#![doc = include_str!("../README.md")]
//! ## feature flags
#![cfg_attr(
    feature = "document-features",
    doc = document_features::document_features!()
)]
#![cfg_attr(not(test), no_std)]

extern crate alloc;

use bevy_app::prelude::*;
use bevy_ecs::prelude::*;

#[cfg(feature = "builder")]
pub mod builder;
pub mod graph;
pub mod signal;
pub mod signal_map;
pub mod signal_vec;
#[allow(missing_docs)]
pub mod utils;

/// Includes the systems required for [jonmo](crate) to function.
#[derive(Default)]
pub struct JonmoPlugin;

/// [`SystemSet`] that can be used to schedule systems around signal processing.
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
pub struct SignalProcessing;

impl Plugin for JonmoPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(
            Last,
            (
                (
                    signal_vec::trigger_replays::<signal_vec::VecReplayTrigger>,
                    signal_vec::trigger_replays::<signal_map::MapReplayTrigger>,
                ),
                graph::process_signal_graph,
                (
                    graph::despawn_stale_signals,
                    signal_vec::despawn_stale_mutable_vecs,
                    signal_map::despawn_stale_mutable_btree_maps,
                ),
            )
                .chain()
                .in_set(SignalProcessing),
        );
    }
}

/// `use jonmo::prelude::*;` imports everything one needs to use start using [jonmo](crate).
pub mod prelude {
    #[cfg(feature = "builder")]
    pub use crate::builder::JonmoBuilder;
    pub use crate::{
        JonmoPlugin,
        graph::SignalHandles,
        signal::{IntoSignalEither, Signal, SignalBuilder, SignalEither, SignalExt},
        signal_map::{MutableBTreeMap, MutableBTreeMapBuilder, MutableBTreeMapData, SignalMap, SignalMapExt},
        signal_vec::{
            IntoSignalVecEither, MutableVec, MutableVecBuilder, MutableVecData, SignalVec, SignalVecEither,
            SignalVecExt,
        },
        utils::{LazyEntity, clone},
    };
    #[doc(no_inline)]
    pub use apply::{Also, Apply};
}
