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

#[derive(Debug, Clone, Serialize)]
pub struct ListParams {
    /// Required: the review whose versions to list.
    ///
    /// Required.
    pub review_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 `50`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}

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

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

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

impl<'a> WorkflowReviewVersionsApi<'a> {
    /// List Review Versions
    ///
    /// List versions for one review.
    ///
    /// `review_id` is required by design — listing versions across all reviews
    /// has no product use and would expose a needlessly wide query surface.
    pub async fn list(&self, params: ListParams) -> Result<WorkflowReviewVersionList, 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<WorkflowReviewVersionList, Error> {
        let path = "/v1/workflows/reviews/versions".to_string();
        let method = http::Method::GET;
        self.client
            .request_page(method, &path, &params, "after", options)
            .await
    }

    /// Create Review Version
    ///
    /// Create one immutable, content-addressed review version.
    pub async fn create(&self, params: CreateParams) -> Result<ReviewVersion, 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<ReviewVersion, Error> {
        let path = "/v1/workflows/reviews/versions".to_string();
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Get Review Version
    ///
    /// Read one review version by its content-addressed id.
    pub async fn get(&self, version_id: &str) -> Result<ReviewVersion, Error> {
        self.get_with_options(version_id, None).await
    }

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