sellapp-sdk 0.1.1

Official Rust SDK for the SellApp API: manage products, orders, subscriptions, and customers.
// This file is auto-generated by oagen. Do not edit.

use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
#[allow(unused_imports)]
use serde::Serialize;

pub struct PromotionsPhasesApi<'a> {
    pub(crate) client: &'a Client,
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct ListParams {
    /// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "X-STORE")]
    pub x_store: Option<String>,
}

#[derive(Debug, Clone, Serialize)]
pub struct ReplaceParams {
    /// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "X-STORE")]
    pub x_store: Option<String>,
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: SdkReplacePromotionPhasesRequestApplicationJson,
}

impl ReplaceParams {
    /// Construct a new `ReplaceParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: SdkReplacePromotionPhasesRequestApplicationJson) -> Self {
        Self {
            x_store: Default::default(),
            body,
        }
    }
}

impl<'a> PromotionsPhasesApi<'a> {
    /// List promotion phases
    ///
    /// List a promotion's active phases in evaluation order. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
    pub async fn list(
        &self,
        promotion: &str,
        params: ListParams,
    ) -> Result<SdkListPromotionPhasesResponseValue200ApplicationJson, Error> {
        self.list_with_options(promotion, params, None).await
    }

    /// Variant of [`Self::list`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_with_options(
        &self,
        promotion: &str,
        params: ListParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkListPromotionPhasesResponseValue200ApplicationJson, Error> {
        self.list_raw(promotion, params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn list_raw(
        &self,
        promotion: &str,
        params: ListParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkListPromotionPhasesResponseValue200ApplicationJson>, Error>
    {
        let promotion = crate::client::path_segment(promotion);
        let path = format!("/v2/promotions/{promotion}/phases");
        let method = http::Method::GET;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("listPromotionPhases".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(
                method,
                &path,
                &params,
                options,
                "GET /v2/promotions/{promotion}/phases",
            )
            .await
    }

    /// Replace promotion phases
    ///
    /// Replace the complete phase set. Array order becomes phase position; at least one phase is required. Historical referenced phases remain soft-deleted. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
    pub async fn replace(
        &self,
        promotion: &str,
        params: ReplaceParams,
    ) -> Result<SdkReplacePromotionPhasesResponseValue200ApplicationJson, Error> {
        self.replace_with_options(promotion, params, None).await
    }

    /// Variant of [`Self::replace`] that accepts per-request [`crate::RequestOptions`].
    pub async fn replace_with_options(
        &self,
        promotion: &str,
        params: ReplaceParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkReplacePromotionPhasesResponseValue200ApplicationJson, Error> {
        self.replace_raw(promotion, params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn replace_raw(
        &self,
        promotion: &str,
        params: ReplaceParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkReplacePromotionPhasesResponseValue200ApplicationJson>, Error>
    {
        let promotion = crate::client::path_segment(promotion);
        let path = format!("/v2/promotions/{promotion}/phases");
        let method = http::Method::PUT;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("replacePromotionPhases".to_string());
        let options = Some(&merged);
        self.client
            .request_with_body_schema_opts_raw(
                method,
                &path,
                &params,
                Some(&params.body),
                options,
                "PUT /v2/promotions/{promotion}/phases",
            )
            .await
    }
}