use serde::de::DeserializeOwned;
use crate::types::InteractionResponse;
use super::{ComponentCtx, HandlerError, ModalCtx, custom_id};
pub trait ComponentDefinition {
const PREFIX: &'static str;
}
pub trait ComponentHandler<S>: ComponentDefinition {
fn invoke(
ctx: ComponentCtx<'_, S>,
fields: Option<&str>,
) -> impl Future<Output = Result<InteractionResponse, HandlerError>> + Send;
}
pub trait ModalDefinition {
const PREFIX: &'static str;
}
pub trait ModalHandler<S>: ModalDefinition {
fn invoke(
ctx: ModalCtx<'_, S>,
fields: Option<&str>,
) -> impl Future<Output = Result<InteractionResponse, HandlerError>> + Send;
}
#[doc(hidden)]
pub fn decode_state<T: DeserializeOwned>(
prefix: &str,
fields: Option<&str>,
) -> Result<T, HandlerError> {
custom_id::decode(fields).map_err(|e| HandlerError::new(format!("`{prefix}` {e}")))
}