// 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 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.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub block_id: Option<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). Each step hydrates its handle payloads from the artifact store, so raise it deliberately for larger pages and use cursor pagination for the rest.
    ///
    /// Defaults to `20`.
    #[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(),
            step_id: Default::default(),
            block_type: Default::default(),
            status: Default::default(),
            before: Default::default(),
            after: Default::default(),
            limit: Some(20),
        }
    }
}

#[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_page(method, &path, &params, "after", options)
            .await
    }

    /// Get Workflow Step
    ///
    /// Get one step by its step id.
    ///
    /// Returns the same step shape as `GET /workflows/steps`.
    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
    }
}
