use crate::api::api_get;
use crate::{
api::{ApiClient, ApiError},
models::CustomField,
};
use futures_util::{StreamExt, pin_mut};
pub async fn list_custom_fields(
client: &ApiClient,
workspace_gid: &str,
limit: Option<usize>,
) -> Result<Vec<CustomField>, ApiError> {
let endpoint = format!("/workspaces/{workspace_gid}/custom_fields");
let stream = client.paginate_with_limit::<CustomField>(&endpoint, vec![], limit);
pin_mut!(stream);
let mut fields = Vec::new();
while let Some(page) = stream.next().await {
let mut page = page?;
fields.append(&mut page);
}
Ok(fields)
}
pub async fn get_custom_field(
client: &ApiClient,
field_gid: &str,
) -> Result<CustomField, ApiError> {
api_get(client, &format!("/custom_fields/{field_gid}")).await
}