// 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 crate::resources::workflow_eval_run_results::WorkflowEvalRunResultsApi;
use crate::resources::workflow_eval_runs::WorkflowEvalRunsApi;
#[allow(unused_imports)]
use serde::Serialize;

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

#[derive(Debug, Clone, Serialize)]
pub struct ListParams {
    /// Required.
    pub workflow_id: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub target_block_id: 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<WorkflowEvalsOrder>,
}

impl ListParams {
    /// Construct a new `ListParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(workflow_id: impl Into<String>) -> Self {
        Self {
            workflow_id: workflow_id.into(),
            target_block_id: Default::default(),
            before: Default::default(),
            after: Default::default(),
            limit: Some(50),
            order: Some(WorkflowEvalsOrder::Desc),
        }
    }
}

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

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

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

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

impl<'a> WorkflowEvalsApi<'a> {
    /// Access the `results` sub-resource.
    pub fn results(&self) -> WorkflowEvalRunResultsApi<'a> {
        WorkflowEvalRunResultsApi {
            client: self.client,
        }
    }

    /// Access the `runs` sub-resource.
    pub fn runs(&self) -> WorkflowEvalRunsApi<'a> {
        WorkflowEvalRunsApi {
            client: self.client,
        }
    }

    /// List Workflow Evals
    ///
    /// List workflow evals.
    ///
    /// Requires `workflow_id` and returns its saved evals as a cursor-paginated
    /// list, each with its latest-run summaries and drift status. Optionally
    /// filter to one block with `target_block_id`. Returns 404 if the workflow
    /// does not exist.
    pub async fn list(&self, params: ListParams) -> Result<WorkflowEvalList, 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<WorkflowEvalList, Error> {
        let path = "/v1/workflows/evals".to_string();
        let method = http::Method::GET;
        self.client
            .request_page(method, &path, &params, "after", options)
            .await
    }

    /// Create Workflow Eval
    ///
    /// Create a workflow eval.
    ///
    /// Pins an expected outcome for one block in a workflow. Provide the
    /// `workflow_id`, the `target` block, an `assertion` describing the expected
    /// output, and a `source` of eval inputs (explicit handle inputs or a capture
    /// from a prior run/step). Returns the created eval with status 201.
    pub async fn create(&self, params: CreateParams) -> Result<WorkflowEval, 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<WorkflowEval, Error> {
        let path = "/v1/workflows/evals".to_string();
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Get Workflow Eval
    ///
    /// Retrieve a single workflow eval.
    ///
    /// Identified by `eval_id`. Returns the eval with its target block,
    /// assertion, input source, and latest-run summaries. Returns 404 if no eval
    /// with that ID exists.
    pub async fn get(&self, eval_id: &str) -> Result<WorkflowEval, Error> {
        self.get_with_options(eval_id, None).await
    }

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

    /// Update Workflow Eval
    ///
    /// Update a workflow eval.
    ///
    /// Identified by `eval_id`. Send any of `name`, `assertion`, or `source`;
    /// omitted fields are left unchanged. Returns the updated eval.
    pub async fn update(&self, eval_id: &str, params: UpdateParams) -> Result<WorkflowEval, Error> {
        self.update_with_options(eval_id, params, None).await
    }

    /// Variant of [`Self::update`] that accepts per-request [`crate::RequestOptions`].
    pub async fn update_with_options(
        &self,
        eval_id: &str,
        params: UpdateParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<WorkflowEval, Error> {
        let eval_id = crate::client::path_segment(eval_id);
        let path = format!("/v1/workflows/evals/{eval_id}");
        let method = http::Method::PATCH;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Delete Workflow Eval
    ///
    /// Delete a workflow eval.
    ///
    /// Identified by `eval_id`. Returns 204 on success and 404 if no eval with
    /// that ID exists.
    pub async fn delete(&self, eval_id: &str) -> Result<(), Error> {
        self.delete_with_options(eval_id, None).await
    }

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