use std::future::{Future, IntoFuture};
use serde::Serialize;
use typed_builder::TypedBuilder;
use crate::{error::ZarinResult, results::unverified::Unverified, ZarinpalClient};
use super::ApiMethod;
#[derive(Debug, Clone, Serialize, TypedBuilder)]
pub struct UnverifiedRequests<'z, Z: ZarinpalClient> {
#[builder(default, setter(strip_option, into))]
merchant_id: Option<String>,
#[serde(skip_serializing)]
#[builder(setter(strip_option))]
zarinpal: Option<&'z Z>,
}
impl<'z, Z: ZarinpalClient + Sync + Send> IntoFuture for UnverifiedRequests<'z, Z> {
type Output = ZarinResult<Unverified>;
type IntoFuture = ::core::pin::Pin<Box<dyn Future<Output = Self::Output> + Send + 'z>>;
fn into_future(mut self) -> Self::IntoFuture {
let zarinpal = std::mem::take(&mut self.zarinpal).unwrap(); Box::pin(zarinpal.send(self))
}
}
impl<'z, Z: ZarinpalClient> ApiMethod for UnverifiedRequests<'z, Z> {
const PATH: &'static str = "pg/v4/payment/unVerified.json";
type Result = Unverified;
fn set_merchant_id_if_needed(&mut self, merchant_id: impl Into<String>) {
match self.merchant_id {
None => self.merchant_id = Some(merchant_id.into()),
_ => (),
}
}
}