use capy_core::Result;
use sea_orm::ConnectionTrait;
use std::future::Future;
pub trait Factory: Sized {
type Model;
fn create<C: ConnectionTrait>(
self,
connection: &C,
) -> impl Future<Output = Result<Self::Model>> + Send;
}
pub struct FactoryBuilder<'a, F, C> {
factory: F,
connection: &'a C,
}
impl<'a, F: Factory, C: ConnectionTrait> FactoryBuilder<'a, F, C> {
pub fn new(factory: F, connection: &'a C) -> Self {
Self {
factory,
connection,
}
}
pub fn with(mut self, customize: impl FnOnce(&mut F)) -> Self {
customize(&mut self.factory);
self
}
pub async fn create(self) -> Result<F::Model> {
self.factory.create(self.connection).await
}
}