mod batch;
mod batch_builders;
pub(crate) mod batch_queries;
mod converters;
mod single;
use crate::models::a2a::Task;
use crate::repository::content::ArtifactRepository;
use sqlx::PgPool;
use std::sync::Arc;
use systemprompt_database::DbPool;
use systemprompt_identifiers::TaskId;
use systemprompt_traits::RepositoryError;
#[derive(Debug, Clone)]
pub struct TaskConstructor {
pool: Arc<PgPool>,
db_pool: DbPool,
artifact_repo: ArtifactRepository,
}
impl TaskConstructor {
pub fn new(db: &DbPool) -> anyhow::Result<Self> {
let pool = db.pool_arc()?;
let artifact_repo = ArtifactRepository::new(db)?;
Ok(Self {
pool,
db_pool: Arc::clone(db),
artifact_repo,
})
}
pub(crate) const fn pool(&self) -> &Arc<PgPool> {
&self.pool
}
pub(crate) const fn artifact_repo(&self) -> &ArtifactRepository {
&self.artifact_repo
}
pub(crate) const fn db_pool(&self) -> &DbPool {
&self.db_pool
}
pub async fn construct_task_from_task_id(
&self,
task_id: &TaskId,
) -> Result<Task, RepositoryError> {
single::construct_task_from_task_id(self, task_id).await
}
pub async fn construct_tasks_batch(
&self,
task_ids: &[TaskId],
) -> Result<Vec<Task>, RepositoryError> {
batch::construct_tasks_batch(self, task_ids).await
}
}