// Code generated by oagen. DO NOT EDIT.

use crate::client::Retab;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
#[allow(unused_imports)]
use serde::Serialize;

pub struct WorkflowArtifactsApi<'a> {
    pub(crate) client: &'a Retab,
}

#[derive(Debug, Clone, Serialize)]
pub struct ListParams {
    /// Workflow run ID whose artifacts should be listed. Required unless `step_id` is provided.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub run_id: Option<String>,
    /// Optional artifact operation filter
    #[serde(skip_serializing_if = "Option::is_none")]
    pub operation: Option<WorkflowArtifactsOperation>,
    /// Optional block_id or step_id filter
    #[serde(skip_serializing_if = "Option::is_none")]
    pub block_id: Option<String>,
    /// Optional step id filter. When provided, returns the single artifact attached to that step (or an empty list if the step has no artifact). `run_id` is not required when `step_id` is set — it is resolved from the step record.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub step_id: Option<String>,
    /// Step id cursor: return the page before this step (mutually exclusive with `after`). Ignored when `step_id` is set.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// Step id cursor: return the page after this step (mutually exclusive with `before`). Ignored when `step_id` is set.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub after: Option<String>,
    /// Maximum number of artifacts to return per page (1-200). Ignored when `step_id` is set (that path returns the single attached artifact).
    ///
    /// Defaults to `100`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}

impl Default for ListParams {
    #[allow(deprecated)]
    fn default() -> Self {
        Self {
            run_id: Default::default(),
            operation: Default::default(),
            block_id: Default::default(),
            step_id: Default::default(),
            before: Default::default(),
            after: Default::default(),
            limit: Some(100),
        }
    }
}

impl<'a> WorkflowArtifactsApi<'a> {
    /// List Workflow Artifacts
    ///
    /// List artifacts produced by a workflow run.
    ///
    /// Paginated by the producing step's `step_id` (sorted by `started_at`
    /// ascending). Pass `after` for the next page, `before` for the previous
    /// page — mutually exclusive. `step_id` short-circuits pagination and
    /// returns the single attached artifact.
    ///
    /// Filters: provide either `run_id` (list all artifacts in a run) or
    /// `step_id` (single-step lookup). When both are absent the request is
    /// rejected with 400.
    pub async fn list(&self, params: ListParams) -> Result<WorkflowArtifactList, Error> {
        self.list_with_options(params, None).await
    }

    /// Variant of [`Self::list`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_with_options(
        &self,
        params: ListParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<WorkflowArtifactList, Error> {
        let path = "/v1/workflows/artifacts".to_string();
        let method = http::Method::GET;
        self.client
            .request_page(method, &path, &params, "after", options)
            .await
    }

    /// Get Workflow Artifact By Id
    ///
    /// Get one workflow artifact by id.
    ///
    /// The artifact kind is derived from the id prefix (`extr_…` → extraction,
    /// `clss_…` → classification, etc.).
    pub async fn get(
        &self,
        artifact_id: &str,
    ) -> Result<GetWorkflowArtifactByIdResponseOneOf, Error> {
        self.get_with_options(artifact_id, None).await
    }

    /// Variant of [`Self::get`] that accepts per-request [`crate::RequestOptions`].
    pub async fn get_with_options(
        &self,
        artifact_id: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<GetWorkflowArtifactByIdResponseOneOf, Error> {
        let artifact_id = crate::client::path_segment(artifact_id);
        let path = format!("/v1/workflows/artifacts/{artifact_id}");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &(), options)
            .await
    }
}
