// 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 serde::Serialize;

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

#[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 }
    }
}

#[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 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 }
    }
}

impl<'a> WorkflowSpecsApi<'a> {
    /// Validate Workflow Spec
    ///
    /// Validate declarative YAML without mutating workflow state.
    ///
    /// Contract:
    /// - validate, plan, and apply agree on whether a spec is acceptable: any
    /// severity=error diagnostic — whether emitted at parse time as a
    /// DeclarativeWorkflowError or bumped during compile/diagnose — raises
    /// HTTP 400 with the structured error issues
    /// - warnings do not make the document invalid; warning-only specs return
    /// HTTP 200 with `is_valid=True` and the warning issues in `diagnostics`
    /// - counts reflect the canonical compiled graph, not raw authored block count
    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
    }

    /// Plan Workflow Spec
    ///
    /// Compute the declarative reconcile plan against the current draft workflow.
    ///
    /// Contract:
    /// - plan compares authored YAML against current draft state
    /// - canonical exported YAML should plan as `noop` against the same draft
    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
    }

    /// Apply Workflow Spec
    ///
    /// Apply declarative YAML to draft workflow state.
    ///
    /// Contract:
    /// - apply writes canonical draft state, not authored formatting
    /// - re-applying canonical exported YAML against unchanged draft state should
    /// return 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
    }

    /// 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/{workflow_id}/spec");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &(), options)
            .await
    }
}
