use chrono::{DateTime, Utc};
use turul_a2a_types::{Task, TaskState};
use super::error::A2aStorageError;
pub const DEFAULT_PAGE_SIZE: i32 = 50;
pub const MAX_PAGE_SIZE: i32 = 100;
pub(crate) fn push_config_page_size(requested: Option<i32>) -> i32 {
match requested {
Some(n) if n > 0 => n.min(MAX_PAGE_SIZE),
_ => DEFAULT_PAGE_SIZE,
}
}
#[derive(Debug, Clone, Default)]
pub struct TaskFilter {
pub tenant: Option<String>,
pub owner: Option<String>,
pub context_id: Option<String>,
pub status: Option<TaskState>,
pub page_size: Option<i32>,
pub page_token: Option<String>,
pub history_length: Option<i32>,
pub status_timestamp_after: Option<DateTime<Utc>>,
pub include_artifacts: Option<bool>,
}
impl TaskFilter {
pub fn resolved_page_size(&self) -> Result<i32, A2aStorageError> {
match self.page_size {
None => Ok(DEFAULT_PAGE_SIZE),
Some(n) if (1..=MAX_PAGE_SIZE).contains(&n) => Ok(n),
Some(n) => Err(A2aStorageError::InvalidListRequest(format!(
"pageSize must be between 1 and {MAX_PAGE_SIZE} inclusive, got {n}"
))),
}
}
pub(crate) fn admits_status_time(&self, task: &Task) -> bool {
self.status_timestamp_after.is_none_or(|after| {
super::status_time::sort_key(task) >= super::status_time::key_of(&after)
})
}
}
#[derive(Debug, Clone)]
pub struct TaskListPage {
pub tasks: Vec<Task>,
pub next_page_token: String,
pub page_size: i32,
pub total_size: i32,
}
#[derive(Debug, Clone)]
pub struct PushConfigListPage {
pub configs: Vec<turul_a2a_proto::TaskPushNotificationConfig>,
pub next_page_token: String,
}