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

#[derive(Debug, Clone, Serialize)]
pub struct ListParams {
    /// Required.
    pub run_id: 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 `100`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Defaults to `desc`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order: Option<ExperimentRunResultsOrder>,
}

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

impl<'a> ExperimentRunResultsApi<'a> {
    /// List Experiment Results
    ///
    /// List per-document results for an experiment run.
    ///
    /// Requires the `run_id` query parameter. Returns one result row per document
    /// in the run, with each row's lifecycle status, timing, and produced
    /// artifact, as a cursor-paginated list.
    pub async fn list(&self, params: ListParams) -> Result<WorkflowExperimentResultList, 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<WorkflowExperimentResultList, Error> {
        let path = "/v1/workflows/experiments/results".to_string();
        let method = http::Method::GET;
        self.client
            .request_page(method, &path, &params, "after", options)
            .await
    }

    /// Get Experiment Result
    ///
    /// Retrieve a single experiment result.
    ///
    /// Identified by `result_id`. Returns the per-document result with its
    /// lifecycle status, timing, and produced artifact. Returns 404 if no result
    /// with that ID exists.
    pub async fn get(&self, result_id: &str) -> Result<ExperimentResult, Error> {
        self.get_with_options(result_id, None).await
    }

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