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

#[derive(Debug, Clone, Serialize)]
pub struct ListParams {
    /// Filter by affiliate program status.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<AffiliatesStatus>,
    /// Search affiliate email addresses and profile identifiers.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub search: Option<String>,
    /// Number of items to return per page.
    ///
    /// Defaults to `15`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Page number to return.
    ///
    /// Defaults to `1`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page: Option<i64>,
    /// 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>,
}

impl Default for ListParams {
    #[allow(deprecated)]
    fn default() -> Self {
        Self {
            status: Default::default(),
            search: Default::default(),
            limit: Some(15),
            page: Some(1),
            x_store: Default::default(),
        }
    }
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct GetParams {
    /// 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 UpdateParams {
    /// 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: SdkUpdateAffiliateStatusRequestApplicationJson,
}

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

impl<'a> AffiliatesApi<'a> {
    /// List affiliates
    ///
    /// List store affiliate memberships, approved profile details, referral counts, and integer USD-cent balances. Requires the `affiliate` ability. 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,
        params: ListParams,
    ) -> Result<SdkListAffiliatesResponseValue200ApplicationJson, 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<SdkListAffiliatesResponseValue200ApplicationJson, Error> {
        self.list_raw(params, options)
            .await
            .map(|response| response.data)
    }

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

    /// Retrieve an affiliate
    ///
    /// Retrieve one store-scoped affiliate, profile, balances, and counts. Requires the `affiliate` ability. 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 get(
        &self,
        affiliate: &str,
        params: GetParams,
    ) -> Result<SdkGetAffiliateResponseValue200ApplicationJson, Error> {
        self.get_with_options(affiliate, params, None).await
    }

    /// Variant of [`Self::get`] that accepts per-request [`crate::RequestOptions`].
    pub async fn get_with_options(
        &self,
        affiliate: &str,
        params: GetParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkGetAffiliateResponseValue200ApplicationJson, Error> {
        self.get_raw(affiliate, params, options)
            .await
            .map(|response| response.data)
    }

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

    /// Update affiliate status
    ///
    /// Approve, disable, re-enable, or reject an affiliate through its valid state transition. Requires `affiliate` and `affiliate:write`; pending invitations cannot be approved until an application is submitted. 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 update(
        &self,
        affiliate: &str,
        params: UpdateParams,
    ) -> Result<SdkUpdateAffiliateStatusResponseValue200ApplicationJson, Error> {
        self.update_with_options(affiliate, params, None).await
    }

    /// Variant of [`Self::update`] that accepts per-request [`crate::RequestOptions`].
    pub async fn update_with_options(
        &self,
        affiliate: &str,
        params: UpdateParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkUpdateAffiliateStatusResponseValue200ApplicationJson, Error> {
        self.update_raw(affiliate, params, options)
            .await
            .map(|response| response.data)
    }

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