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 ProductVariantsApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Serialize)]
pub struct ListParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub page: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub with_drafts: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub only_drafts: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
}
impl Default for ListParams {
#[allow(deprecated)]
fn default() -> Self {
Self {
limit: Some(15),
page: Some(1),
with_drafts: Default::default(),
only_drafts: Default::default(),
x_store: Default::default(),
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
#[serde(skip)]
pub body: SdkCreateProductVariantRequestApplicationJson,
}
impl CreateParams {
#[allow(deprecated)]
pub fn new(body: SdkCreateProductVariantRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub with_drafts: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub only_drafts: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct ReplaceParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
#[serde(skip)]
pub body: SdkReplaceProductVariantWithPutRequestApplicationJson,
}
impl ReplaceParams {
#[allow(deprecated)]
pub fn new(body: SdkReplaceProductVariantWithPutRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct UpdateParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
#[serde(skip)]
pub body: SdkUpdateProductVariantRequestApplicationJson,
}
impl UpdateParams {
#[allow(deprecated)]
pub fn new(body: SdkUpdateProductVariantRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct DeleteParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct SearchParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
#[serde(skip)]
pub body: SdkSearchProductVariantsRequestApplicationJson,
}
impl SearchParams {
#[allow(deprecated)]
pub fn new(body: SdkSearchProductVariantsRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct BatchCreateParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
#[serde(skip)]
pub body: SdkBatchCreateProductVariantsRequestApplicationJson,
}
impl BatchCreateParams {
#[allow(deprecated)]
pub fn new(body: SdkBatchCreateProductVariantsRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct BatchUpdateParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
#[serde(skip)]
pub body: SdkBatchUpdateProductVariantsRequestApplicationJson,
}
impl BatchUpdateParams {
#[allow(deprecated)]
pub fn new(body: SdkBatchUpdateProductVariantsRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct BatchDeleteParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
#[serde(skip)]
pub body: SdkBatchDeleteCouponsRequestApplicationJson,
}
impl BatchDeleteParams {
#[allow(deprecated)]
pub fn new(body: SdkBatchDeleteCouponsRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
impl<'a> ProductVariantsApi<'a> {
pub async fn list(
&self,
product: &str,
params: ListParams,
) -> Result<SdkListProductVariantsResponseValue200ApplicationJson, Error> {
self.list_with_options(product, params, None).await
}
pub async fn list_with_options(
&self,
product: &str,
params: ListParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkListProductVariantsResponseValue200ApplicationJson, Error> {
self.list_raw(product, params, options)
.await
.map(|response| response.data)
}
pub async fn list_raw(
&self,
product: &str,
params: ListParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkListProductVariantsResponseValue200ApplicationJson>, Error>
{
let product = crate::client::path_segment(product);
let path = format!("/v2/products/{product}/variants");
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("listProductVariants".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
¶ms,
options,
"GET /v2/products/{product}/variants",
)
.await
}
pub async fn create(
&self,
product: &str,
params: CreateParams,
) -> Result<SdkCreateProductVariantResponseValue201ApplicationJson, Error> {
self.create_with_options(product, params, None).await
}
pub async fn create_with_options(
&self,
product: &str,
params: CreateParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkCreateProductVariantResponseValue201ApplicationJson, Error> {
self.create_raw(product, params, options)
.await
.map(|response| response.data)
}
pub async fn create_raw(
&self,
product: &str,
params: CreateParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkCreateProductVariantResponseValue201ApplicationJson>, Error>
{
let product = crate::client::path_segment(product);
let path = format!("/v2/products/{product}/variants");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("createProductVariant".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/products/{product}/variants",
)
.await
}
pub async fn get(
&self,
product: &str,
variant: &str,
params: GetParams,
) -> Result<SdkGetProductVariantResponseValue200ApplicationJson, Error> {
self.get_with_options(product, variant, params, None).await
}
pub async fn get_with_options(
&self,
product: &str,
variant: &str,
params: GetParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkGetProductVariantResponseValue200ApplicationJson, Error> {
self.get_raw(product, variant, params, options)
.await
.map(|response| response.data)
}
pub async fn get_raw(
&self,
product: &str,
variant: &str,
params: GetParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkGetProductVariantResponseValue200ApplicationJson>, Error>
{
let product = crate::client::path_segment(product);
let variant = crate::client::path_segment(variant);
let path = format!("/v2/products/{product}/variants/{variant}");
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("getProductVariant".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
¶ms,
options,
"GET /v2/products/{product}/variants/{variant}",
)
.await
}
pub async fn replace(
&self,
product: &str,
variant: &str,
params: ReplaceParams,
) -> Result<SdkReplaceProductVariantWithPutResponseValue200ApplicationJson, Error> {
self.replace_with_options(product, variant, params, None)
.await
}
pub async fn replace_with_options(
&self,
product: &str,
variant: &str,
params: ReplaceParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkReplaceProductVariantWithPutResponseValue200ApplicationJson, Error> {
self.replace_raw(product, variant, params, options)
.await
.map(|response| response.data)
}
pub async fn replace_raw(
&self,
product: &str,
variant: &str,
params: ReplaceParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkReplaceProductVariantWithPutResponseValue200ApplicationJson>,
Error,
> {
let product = crate::client::path_segment(product);
let variant = crate::client::path_segment(variant);
let path = format!("/v2/products/{product}/variants/{variant}");
let method = http::Method::PUT;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("replaceProductVariantWithPut".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"PUT /v2/products/{product}/variants/{variant}",
)
.await
}
pub async fn update(
&self,
product: &str,
variant: &str,
params: UpdateParams,
) -> Result<SdkUpdateProductVariantResponseValue200ApplicationJson, Error> {
self.update_with_options(product, variant, params, None)
.await
}
pub async fn update_with_options(
&self,
product: &str,
variant: &str,
params: UpdateParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkUpdateProductVariantResponseValue200ApplicationJson, Error> {
self.update_raw(product, variant, params, options)
.await
.map(|response| response.data)
}
pub async fn update_raw(
&self,
product: &str,
variant: &str,
params: UpdateParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkUpdateProductVariantResponseValue200ApplicationJson>, Error>
{
let product = crate::client::path_segment(product);
let variant = crate::client::path_segment(variant);
let path = format!("/v2/products/{product}/variants/{variant}");
let method = http::Method::PATCH;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("updateProductVariant".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"PATCH /v2/products/{product}/variants/{variant}",
)
.await
}
pub async fn delete(
&self,
product: &str,
variant: &str,
params: DeleteParams,
) -> Result<SdkDeleteProductVariantResponseValue200ApplicationJson, Error> {
self.delete_with_options(product, variant, params, None)
.await
}
pub async fn delete_with_options(
&self,
product: &str,
variant: &str,
params: DeleteParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkDeleteProductVariantResponseValue200ApplicationJson, Error> {
self.delete_raw(product, variant, params, options)
.await
.map(|response| response.data)
}
pub async fn delete_raw(
&self,
product: &str,
variant: &str,
params: DeleteParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkDeleteProductVariantResponseValue200ApplicationJson>, Error>
{
let product = crate::client::path_segment(product);
let variant = crate::client::path_segment(variant);
let path = format!("/v2/products/{product}/variants/{variant}");
let method = http::Method::DELETE;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("deleteProductVariant".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
¶ms,
options,
"DELETE /v2/products/{product}/variants/{variant}",
)
.await
}
pub async fn search(
&self,
product: &str,
params: SearchParams,
) -> Result<SdkSearchProductVariantsResponseValue200ApplicationJson, Error> {
self.search_with_options(product, params, None).await
}
pub async fn search_with_options(
&self,
product: &str,
params: SearchParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkSearchProductVariantsResponseValue200ApplicationJson, Error> {
self.search_raw(product, params, options)
.await
.map(|response| response.data)
}
pub async fn search_raw(
&self,
product: &str,
params: SearchParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkSearchProductVariantsResponseValue200ApplicationJson>, Error>
{
let product = crate::client::path_segment(product);
let path = format!("/v2/products/{product}/variants/search");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("searchProductVariants".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/products/{product}/variants/search",
)
.await
}
pub async fn batch_create(
&self,
product: &str,
params: BatchCreateParams,
) -> Result<SdkBatchCreateProductVariantsResponseValue200ApplicationJson, Error> {
self.batch_create_with_options(product, params, None).await
}
pub async fn batch_create_with_options(
&self,
product: &str,
params: BatchCreateParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkBatchCreateProductVariantsResponseValue200ApplicationJson, Error> {
self.batch_create_raw(product, params, options)
.await
.map(|response| response.data)
}
pub async fn batch_create_raw(
&self,
product: &str,
params: BatchCreateParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkBatchCreateProductVariantsResponseValue200ApplicationJson>,
Error,
> {
let product = crate::client::path_segment(product);
let path = format!("/v2/products/{product}/variants/batch");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("batchCreateProductVariants".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/products/{product}/variants/batch",
)
.await
}
pub async fn batch_update(
&self,
product: &str,
params: BatchUpdateParams,
) -> Result<SdkBatchUpdateProductVariantsResponseValue200ApplicationJson, Error> {
self.batch_update_with_options(product, params, None).await
}
pub async fn batch_update_with_options(
&self,
product: &str,
params: BatchUpdateParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkBatchUpdateProductVariantsResponseValue200ApplicationJson, Error> {
self.batch_update_raw(product, params, options)
.await
.map(|response| response.data)
}
pub async fn batch_update_raw(
&self,
product: &str,
params: BatchUpdateParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkBatchUpdateProductVariantsResponseValue200ApplicationJson>,
Error,
> {
let product = crate::client::path_segment(product);
let path = format!("/v2/products/{product}/variants/batch");
let method = http::Method::PATCH;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("batchUpdateProductVariants".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"PATCH /v2/products/{product}/variants/batch",
)
.await
}
pub async fn batch_delete(
&self,
product: &str,
params: BatchDeleteParams,
) -> Result<SdkBatchDeleteProductVariantsResponseValue200ApplicationJson, Error> {
self.batch_delete_with_options(product, params, None).await
}
pub async fn batch_delete_with_options(
&self,
product: &str,
params: BatchDeleteParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkBatchDeleteProductVariantsResponseValue200ApplicationJson, Error> {
self.batch_delete_raw(product, params, options)
.await
.map(|response| response.data)
}
pub async fn batch_delete_raw(
&self,
product: &str,
params: BatchDeleteParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkBatchDeleteProductVariantsResponseValue200ApplicationJson>,
Error,
> {
let product = crate::client::path_segment(product);
let path = format!("/v2/products/{product}/variants/batch");
let method = http::Method::DELETE;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("batchDeleteProductVariants".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"DELETE /v2/products/{product}/variants/batch",
)
.await
}
}