use std::sync::Arc;
use bitwarden_crypto::KeyStore;
#[cfg(feature = "internal")]
use bitwarden_state::repository::{Repository, RepositoryItem};
use super::Client;
use crate::{client::ApiConfigurations, key_management::KeySlotIds};
pub trait FromClient: Sized {
fn from_client(client: &Client) -> Self;
}
pub trait FromClientPart<T> {
fn get_part(&self) -> T;
}
impl FromClientPart<KeyStore<KeySlotIds>> for Client {
fn get_part(&self) -> KeyStore<KeySlotIds> {
self.internal.get_key_store().clone()
}
}
impl FromClientPart<Arc<ApiConfigurations>> for Client {
fn get_part(&self) -> Arc<ApiConfigurations> {
self.internal.get_api_configurations()
}
}
#[cfg(feature = "internal")]
impl<T: RepositoryItem> FromClientPart<Option<Arc<dyn Repository<T>>>> for Client {
fn get_part(&self) -> Option<Arc<dyn Repository<T>>> {
self.platform().state().get::<T>().ok()
}
}