use std::sync::Arc;
use crate::error::{map_user_err, ManagerError};
use crate::gen::user::apis::configuration::Configuration;
use crate::gen::user::apis::user_api as api;
use crate::gen::user::models;
use crate::retry::{with_retry, RetryPolicy};
pub struct MeResource {
pub(crate) cfg: Arc<Configuration>,
pub(crate) retry: RetryPolicy,
}
impl MeResource {
pub async fn get(&self) -> Result<models::UserItemResponse, ManagerError> {
with_retry(&self.retry, true, || api::get_user(self.cfg.as_ref()))
.await
.map_err(map_user_err)
}
pub async fn customer(&self) -> Result<models::UserCustomerItemResponse, ManagerError> {
with_retry(&self.retry, true, || {
api::get_user_customer(self.cfg.as_ref())
})
.await
.map_err(map_user_err)
}
pub async fn accounts(&self) -> Result<Vec<models::Account>, ManagerError> {
let resp = with_retry(&self.retry, true, || api::list_accounts(self.cfg.as_ref()))
.await
.map_err(map_user_err)?;
Ok(resp.items)
}
pub async fn reset_password(&self) -> Result<(), ManagerError> {
with_retry(&self.retry, false, || {
api::reset_password(self.cfg.as_ref())
})
.await
.map_err(map_user_err)?;
Ok(())
}
}