use crate::product::{
Category, CategoryCreate, CategoryUpdate, ExportJob, ExportJobCreate, ImportJob,
ImportJobCreate, ProductCatalog, ProductCatalogCreate, ProductCatalogUpdate, ProductOffering,
ProductOfferingCreate, ProductOfferingPrice, ProductOfferingPriceCreate,
ProductOfferingPriceUpdate, ProductOfferingUpdate, ProductSpecification,
ProductSpecificationCreate, ProductSpecificationUpdate,
};
use super::client::TmfClient;
use super::error::Result;
use super::hub::HubOps;
use super::page::{Page, PageRequest, PageStream, paginate};
use super::patch::Patch;
use super::query::Query;
use super::transport::Transport;
use super::{op_delete, resource_ops, task_ops};
pub const API_PATH: &str = "tmf-api/productCatalogManagement/v5";
pub const SPEC_VERSION: &str = "5.0.0";
const CATALOGS: &str = "productCatalog";
const CATEGORIES: &str = "category";
const OFFERINGS: &str = "productOffering";
const PRICES: &str = "productOfferingPrice";
const SPECIFICATIONS: &str = "productSpecification";
const IMPORT_JOBS: &str = "importJob";
const EXPORT_JOBS: &str = "exportJob";
#[derive(Debug, Clone)]
pub struct ProductCatalogClient {
inner: TmfClient,
}
impl ProductCatalogClient {
pub fn new(base_url: impl Into<String>, transport: impl Transport + 'static) -> Result<Self> {
Ok(Self {
inner: TmfClient::new(base_url, transport)?,
})
}
pub fn from_host(host: &str, transport: impl Transport + 'static) -> Result<Self> {
Self::new(
format!("{}/{API_PATH}", host.trim_end_matches('/')),
transport,
)
}
#[must_use]
pub fn inner(&self) -> &TmfClient {
&self.inner
}
resource_ops!(
OFFERINGS,
read = ProductOffering,
create = ProductOfferingCreate,
update = ProductOfferingUpdate,
list = list_product_offerings,
stream = stream_product_offerings,
get = get_product_offering,
new = create_product_offering,
patch = update_product_offering,
delete = delete_product_offering,
doc = "a product offering"
);
resource_ops!(
SPECIFICATIONS,
read = ProductSpecification,
create = ProductSpecificationCreate,
update = ProductSpecificationUpdate,
list = list_product_specifications,
stream = stream_product_specifications,
get = get_product_specification,
new = create_product_specification,
patch = update_product_specification,
delete = delete_product_specification,
doc = "a product specification"
);
resource_ops!(
PRICES,
read = ProductOfferingPrice,
create = ProductOfferingPriceCreate,
update = ProductOfferingPriceUpdate,
list = list_product_offering_prices,
stream = stream_product_offering_prices,
get = get_product_offering_price,
new = create_product_offering_price,
patch = update_product_offering_price,
delete = delete_product_offering_price,
doc = "a product offering price"
);
resource_ops!(
CATALOGS,
read = ProductCatalog,
create = ProductCatalogCreate,
update = ProductCatalogUpdate,
list = list_product_catalogs,
stream = stream_product_catalogs,
get = get_product_catalog,
new = create_product_catalog,
patch = update_product_catalog,
delete = delete_product_catalog,
doc = "a product catalog"
);
resource_ops!(
CATEGORIES,
read = Category,
create = CategoryCreate,
update = CategoryUpdate,
list = list_categories,
stream = stream_categories,
get = get_category,
new = create_category,
patch = update_category,
delete = delete_category,
doc = "a category"
);
task_ops!(
IMPORT_JOBS,
read = ImportJob,
create = ImportJobCreate,
list = list_import_jobs,
stream = stream_import_jobs,
get = get_import_job,
new = create_import_job,
doc = "an import job"
);
op_delete!(IMPORT_JOBS, delete_import_job, "an import job");
task_ops!(
EXPORT_JOBS,
read = ExportJob,
create = ExportJobCreate,
list = list_export_jobs,
stream = stream_export_jobs,
get = get_export_job,
new = create_export_job,
doc = "an export job"
);
op_delete!(EXPORT_JOBS, delete_export_job, "an export job");
}
impl HubOps for ProductCatalogClient {
fn hub_client(&self) -> &TmfClient {
&self.inner
}
}