use crate::models::*;
use stellar_rust_sdk_derive::pagination;
#[derive(Default, Clone)]
pub struct OfferAccountId(String);
#[derive(Default, Clone)]
pub struct NoOfferAccountId;
#[pagination]
#[derive(Default)]
pub struct OffersForAccountRequest<I> {
account_id: I,
}
impl OffersForAccountRequest<NoOfferAccountId> {
pub fn new() -> Self {
OffersForAccountRequest::default()
}
pub fn set_account_id(
self,
account_id: impl Into<String>
) -> Result<OffersForAccountRequest<OfferAccountId>, String> {
let account_id = account_id.into();
if let Err(e) = is_public_key(&account_id) {
return Err(e.to_string());
}
Ok(OffersForAccountRequest {
account_id: OfferAccountId(account_id),
cursor: self.cursor,
limit: self.limit,
order: self.order,
})
}
}
impl Request for OffersForAccountRequest<OfferAccountId> {
fn get_query_parameters(&self) -> String {
let mut query = String::new();
query.push_str(&format!("{}", self.account_id.0));
query.trim_end_matches('&').to_string()
}
fn build_url(&self, base_url: &str) -> String {
use crate::accounts::ACCOUNTS_PATH;
format!(
"{}/{}/{}/{}",
base_url,
ACCOUNTS_PATH,
self.get_query_parameters(),
super::OFFERS_PATH
)
}
}