// 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 WorkflowEvalRunsApi<'a> {
    pub(crate) client: &'a Retab,
}

#[derive(Debug, Clone, Serialize)]
pub struct ListParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub workflow_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub eval_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub target_block_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub exclude_status: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub trigger_type: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub from_date: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub to_date: Option<String>,
    /// Defaults to `created_at`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sort_by: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub after: Option<String>,
    /// Defaults to `50`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Defaults to `desc`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order: Option<WorkflowEvalRunsOrder>,
}

impl Default for ListParams {
    #[allow(deprecated)]
    fn default() -> Self {
        Self {
            workflow_id: Default::default(),
            eval_id: Default::default(),
            target_block_id: Default::default(),
            status: Default::default(),
            exclude_status: Default::default(),
            trigger_type: Default::default(),
            from_date: Default::default(),
            to_date: Default::default(),
            sort_by: Some("created_at".to_string()),
            before: Default::default(),
            after: Default::default(),
            limit: Some(50),
            order: Some(WorkflowEvalRunsOrder::Desc),
        }
    }
}

#[derive(Debug, Clone, Serialize)]
pub struct CreateParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: CreateWorkflowEvalRunRequest,
}

impl CreateParams {
    /// Construct a new `CreateParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: CreateWorkflowEvalRunRequest) -> Self {
        Self { body }
    }
}

impl<'a> WorkflowEvalRunsApi<'a> {
    /// List Workflow Eval Runs
    ///
    /// List workflow eval runs.
    ///
    /// Optionally filter by `workflow_id`, `eval_id`, `target_block_id`,
    /// `status`/`exclude_status`, `trigger_type`, and a `from_date`/`to_date`
    /// window. Returns a cursor-paginated list ordered by `sort_by` (default
    /// newest first).
    pub async fn list(&self, params: ListParams) -> Result<WorkflowEvalRunList, 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<WorkflowEvalRunList, Error> {
        let path = "/v1/workflows/evals/runs".to_string();
        let method = http::Method::GET;
        self.client
            .request_page(method, &path, &params, "after", options)
            .await
    }

    /// Create Workflow Eval Run
    ///
    /// Create a workflow-scoped eval run.
    ///
    /// `workflow_id` is the execution context. Optional `scope` narrows the
    /// run to one saved eval or one block; omitted scope runs all workflow evals.
    pub async fn create(&self, params: CreateParams) -> Result<WorkflowEvalRun, Error> {
        self.create_with_options(params, None).await
    }

    /// Variant of [`Self::create`] that accepts per-request [`crate::RequestOptions`].
    pub async fn create_with_options(
        &self,
        params: CreateParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<WorkflowEvalRun, Error> {
        let path = "/v1/workflows/evals/runs".to_string();
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Get Workflow Eval Run
    ///
    /// Retrieve a single workflow eval run.
    ///
    /// Identified by `run_id`. Returns the run with its lifecycle status, timing,
    /// and pass/fail counts. Returns 404 if no run with that ID exists.
    pub async fn get(&self, run_id: &str) -> Result<WorkflowEvalRun, Error> {
        self.get_with_options(run_id, None).await
    }

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

    /// Cancel Workflow Eval Run
    ///
    /// Cancel a workflow eval run.
    ///
    /// Identified by `run_id`. Stops the run and returns it with its updated
    /// cancelled lifecycle. Returns 404 if the run does not exist or is not in a
    /// cancellable state.
    pub async fn cancel(&self, run_id: &str) -> Result<WorkflowEvalRun, Error> {
        self.cancel_with_options(run_id, None).await
    }

    /// Variant of [`Self::cancel`] that accepts per-request [`crate::RequestOptions`].
    pub async fn cancel_with_options(
        &self,
        run_id: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<WorkflowEvalRun, Error> {
        let run_id = crate::client::path_segment(run_id);
        let path = format!("/v1/workflows/evals/runs/{run_id}/cancel");
        let method = http::Method::POST;
        self.client
            .request_with_query_opts(method, &path, &(), options)
            .await
    }
}
