use crate::party::{
Individual, IndividualCreate, IndividualUpdate, Organization, OrganizationCreate,
OrganizationUpdate,
};
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::resource_ops;
use super::transport::Transport;
pub const API_PATH: &str = "tmf-api/partyManagement/v5";
pub const SPEC_VERSION: &str = "5.0.0";
const INDIVIDUALS: &str = "individual";
const ORGANIZATIONS: &str = "organization";
#[derive(Debug, Clone)]
pub struct PartyClient {
inner: TmfClient,
}
impl PartyClient {
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!(
INDIVIDUALS,
read = Individual,
create = IndividualCreate,
update = IndividualUpdate,
list = list_individuals,
stream = stream_individuals,
get = get_individual,
new = create_individual,
patch = update_individual,
delete = delete_individual,
doc = "an individual"
);
resource_ops!(
ORGANIZATIONS,
read = Organization,
create = OrganizationCreate,
update = OrganizationUpdate,
list = list_organizations,
stream = stream_organizations,
get = get_organization,
new = create_organization,
patch = update_organization,
delete = delete_organization,
doc = "an organization"
);
}
impl HubOps for PartyClient {
fn hub_client(&self) -> &TmfClient {
&self.inner
}
}