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

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

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

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

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

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

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

impl<'a> WorkflowSpecApi<'a> {
    /// Apply Workflow Spec
    ///
    /// Apply a declarative YAML spec to the draft workflow.
    ///
    /// Re-applying a spec that already matches the draft makes no changes and
    /// returns an empty `resource_changes` list.
    pub async fn apply(&self, params: ApplyParams) -> Result<DeclarativeApplyResponse, Error> {
        self.apply_with_options(params, None).await
    }

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

    /// Plan Workflow Spec
    ///
    /// Preview the changes a declarative YAML spec would make to the draft workflow.
    ///
    /// Compares the spec against the current draft and returns the resulting
    /// changes without applying them. A spec that already matches the draft
    /// plans as a no-op.
    pub async fn plan(&self, params: PlanParams) -> Result<DeclarativePlanResponse, Error> {
        self.plan_with_options(params, None).await
    }

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

    /// Validate Workflow Spec
    ///
    /// Validate declarative YAML without changing the workflow.
    ///
    /// Any error-level diagnostic responds with 400 and the structured issues.
    /// Warnings do not make a spec invalid: a warning-only spec responds with
    /// 200, `is_valid=True`, and the warnings in `diagnostics`.
    pub async fn validate(
        &self,
        params: ValidateParams,
    ) -> Result<DeclarativeValidationResponse, Error> {
        self.validate_with_options(params, None).await
    }

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

    /// Export Workflow Spec
    ///
    /// Export draft workflow state as canonical declarative YAML.
    pub async fn get(&self, workflow_id: &str) -> Result<DeclarativeExportResponse, Error> {
        self.get_with_options(workflow_id, None).await
    }

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