use std::fmt::{Debug, Display};
use async_trait::async_trait;
use dyn_clone::DynClone;
use peace_data::Data;
use peace_item_model::ItemId;
use peace_params::{Params, ParamsSpec};
use peace_resource_rt::{resources::ts::Empty, Resources};
use serde::{de::DeserializeOwned, Serialize};
use crate::{ApplyCheck, FnCtx};
#[async_trait(?Send)]
pub trait Item: DynClone {
type Error: std::error::Error + Send + Sync;
#[cfg(not(feature = "output_progress"))]
type State: Clone
+ Debug
+ Display
+ PartialEq
+ Serialize
+ DeserializeOwned
+ Send
+ Sync
+ 'static;
#[cfg(feature = "output_progress")]
type State: Clone
+ Debug
+ Display
+ PartialEq
+ Serialize
+ DeserializeOwned
+ Send
+ Sync
+ 'static
+ crate::RefInto<peace_item_interaction_model::ItemLocationState>;
type StateDiff: Clone + Debug + Display + Serialize + DeserializeOwned + Send + Sync + 'static;
type Params<'exec>: Params<Spec = ParamsSpec<Self::Params<'exec>>>
+ Clone
+ Debug
+ Serialize
+ DeserializeOwned
+ Send
+ Sync
+ 'static;
type Data<'exec>: Data<'exec>;
fn id(&self) -> &ItemId;
async fn setup(&self, resources: &mut Resources<Empty>) -> Result<(), Self::Error>;
#[cfg(feature = "item_state_example")]
fn state_example(params: &Self::Params<'_>, data: Self::Data<'_>) -> Self::State;
async fn try_state_current(
fn_ctx: FnCtx<'_>,
params_partial: &<Self::Params<'_> as Params>::Partial,
data: Self::Data<'_>,
) -> Result<Option<Self::State>, Self::Error>;
async fn state_current(
fn_ctx: FnCtx<'_>,
params: &Self::Params<'_>,
data: Self::Data<'_>,
) -> Result<Self::State, Self::Error>;
async fn try_state_goal(
fn_ctx: FnCtx<'_>,
params_partial: &<Self::Params<'_> as Params>::Partial,
data: Self::Data<'_>,
) -> Result<Option<Self::State>, Self::Error>;
async fn state_goal(
fn_ctx: FnCtx<'_>,
params: &Self::Params<'_>,
data: Self::Data<'_>,
) -> Result<Self::State, Self::Error>;
async fn state_diff(
params_partial: &<Self::Params<'_> as Params>::Partial,
data: Self::Data<'_>,
state_a: &Self::State,
state_b: &Self::State,
) -> Result<Self::StateDiff, Self::Error>;
async fn state_clean(
params_partial: &<Self::Params<'_> as Params>::Partial,
data: Self::Data<'_>,
) -> Result<Self::State, Self::Error>;
async fn apply_check(
params: &Self::Params<'_>,
data: Self::Data<'_>,
state_current: &Self::State,
state_target: &Self::State,
diff: &Self::StateDiff,
) -> Result<ApplyCheck, Self::Error>;
async fn apply_dry(
fn_ctx: FnCtx<'_>,
params: &Self::Params<'_>,
data: Self::Data<'_>,
state_current: &Self::State,
state_target: &Self::State,
diff: &Self::StateDiff,
) -> Result<Self::State, Self::Error>;
async fn apply(
fn_ctx: FnCtx<'_>,
params: &Self::Params<'_>,
data: Self::Data<'_>,
state_current: &Self::State,
state_target: &Self::State,
diff: &Self::StateDiff,
) -> Result<Self::State, Self::Error>;
#[cfg(feature = "item_interactions")]
fn interactions(
params: &Self::Params<'_>,
data: Self::Data<'_>,
) -> Vec<peace_item_interaction_model::ItemInteraction>;
}