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

#[derive(Debug, Clone, Default, Serialize)]
pub struct ListCustomerEntitlementsParams {
    /// 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, Default, Serialize)]
pub struct ListCustomerEntitlementsByExternalIdParams {
    /// 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<'a> EntitlementsApi<'a> {
    /// List customer entitlements
    ///
    /// Unified access without raw keys, serials, files, dynamic payloads, or seller-only metadata. 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_customer_entitlements(
        &self,
        customer: &str,
        params: ListCustomerEntitlementsParams,
    ) -> Result<SdkListCustomerEntitlementsResponseValue200ApplicationJson, Error> {
        self.list_customer_entitlements_with_options(customer, params, None)
            .await
    }

    /// Variant of [`Self::list_customer_entitlements`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_customer_entitlements_with_options(
        &self,
        customer: &str,
        params: ListCustomerEntitlementsParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkListCustomerEntitlementsResponseValue200ApplicationJson, Error> {
        self.list_customer_entitlements_raw(customer, params, options)
            .await
            .map(|response| response.data)
    }

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

    /// List customer entitlements
    ///
    /// Unified access without raw keys, serials, files, dynamic payloads, or seller-only metadata. 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_customer_entitlements_by_external_id(
        &self,
        external_id: &str,
        params: ListCustomerEntitlementsByExternalIdParams,
    ) -> Result<SdkListCustomerEntitlementsResponseValue200ApplicationJson, Error> {
        self.list_customer_entitlements_by_external_id_with_options(external_id, params, None)
            .await
    }

    /// Variant of [`Self::list_customer_entitlements_by_external_id`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_customer_entitlements_by_external_id_with_options(
        &self,
        external_id: &str,
        params: ListCustomerEntitlementsByExternalIdParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkListCustomerEntitlementsResponseValue200ApplicationJson, Error> {
        self.list_customer_entitlements_by_external_id_raw(external_id, params, options)
            .await
            .map(|response| response.data)
    }

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