// 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::*;
use serde::Serialize;

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

#[derive(Debug, Clone, Serialize)]
pub struct ListParams {
    /// Optional workflow run ID filter.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub run_id: Option<String>,
    /// Optional logical block ID filter (deprecated; prefer ``block_ids`` for multi-value filtering).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub block_id: Option<String>,
    /// Optional logical block ID filter — multi-value. Repeat the query parameter (``?block_ids=a&block_ids=b``) to match any of several blocks. An empty list is treated as no filter. Preferred over the singular ``block_id``.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub block_ids: Option<Vec<String>>,
    /// Optional step ID filter.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub step_id: Option<String>,
    /// Optional block type filter. Repeat the query parameter for multiple values.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub block_type: Option<Vec<String>>,
    /// Optional step lifecycle status filter. Repeat the query parameter for multiple values.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<Vec<String>>,
    /// Step id cursor: return the page before this id (mutually exclusive with ``after``).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// Step id cursor: return the page after this id (mutually exclusive with ``before``).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub after: Option<String>,
    /// Maximum number of steps to return per page (1-1000). Defaults to 200; raise it for run-scoped queries on large DAGs and rely on cursor pagination for the rest.
    ///
    /// Defaults to `200`.
    #[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(),
            block_id: Default::default(),
            block_ids: Default::default(),
            step_id: Default::default(),
            block_type: Default::default(),
            status: Default::default(),
            before: Default::default(),
            after: Default::default(),
            limit: Some(200),
        }
    }
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct GetParams {
    /// Optional workflow run ID disambiguator.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub run_id: Option<String>,
}

impl<'a> WorkflowStepsApi<'a> {
    /// List Workflow Run Steps
    ///
    /// List steps with status and artifact summaries.
    ///
    /// Sorted by ``started_at`` ascending with ``step_id`` as the tiebreaker
    /// (the same compound key the underlying index uses). Pass ``after`` for
    /// the next page, ``before`` for the previous page — mutually exclusive.
    /// ``run_id`` is optional; when omitted the list is scoped to the caller's
    /// organization.
    pub async fn list(&self, params: ListParams) -> Result<WorkflowStepList, 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<WorkflowStepList, Error> {
        let path = "/v1/workflows/steps".to_string();
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &params, options)
            .await
    }

    /// Returns an async [`futures_util::Stream`] that yields every `WorkflowRunStep`
    /// across all pages, advancing the `after` cursor under the hood.
    ///
    /// ```ignore
    /// use futures_util::TryStreamExt;
    /// let all: Vec<WorkflowRunStep> = self
    ///     .list_auto_paging(params)
    ///     .try_collect()
    ///     .await?;
    /// ```
    pub fn list_auto_paging(
        &self,
        params: ListParams,
    ) -> impl futures_util::Stream<Item = Result<WorkflowRunStep, Error>> + '_ {
        crate::pagination::auto_paginate_pages(move |after| {
            let mut params = params.clone();
            params.after = after;
            async move {
                let page = self.list(params).await?;
                Ok((page.data, page.list_metadata.after))
            }
        })
    }

    /// Get Workflow Step
    ///
    /// Get one persisted step document by step id.
    ///
    /// This is the canonical step object shape used by ``GET /workflows/steps``.
    /// It intentionally does not join fingerprint rows or return experiment query
    /// projections.
    pub async fn get(&self, step_id: &str, params: GetParams) -> Result<WorkflowRunStep, Error> {
        self.get_with_options(step_id, params, None).await
    }

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