use serde::{Deserialize, Serialize};
use crate::client::{Client, Response};
use crate::ids::AccountId;
use crate::params::{Expand, Object, Timestamp};
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct AccountLink {
pub created: Timestamp,
pub expires_at: Timestamp,
pub url: String,
}
impl AccountLink {
pub fn create(client: &Client, params: CreateAccountLink<'_>) -> Response<AccountLink> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form("/account_links", ¶ms)
}
}
impl Object for AccountLink {
type Id = ();
fn id(&self) -> Self::Id {}
fn object(&self) -> &'static str {
"account_link"
}
}
#[derive(Clone, Debug, Serialize)]
pub struct CreateAccountLink<'a> {
pub account: AccountId,
#[serde(skip_serializing_if = "Option::is_none")]
pub collect: Option<AccountLinkCollect>,
#[serde(skip_serializing_if = "Option::is_none")]
pub collection_options: Option<CreateAccountLinkCollectionOptions>,
#[serde(skip_serializing_if = "Expand::is_empty")]
pub expand: &'a [&'a str],
#[serde(skip_serializing_if = "Option::is_none")]
pub refresh_url: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub return_url: Option<&'a str>,
#[serde(rename = "type")]
pub type_: AccountLinkType,
}
impl<'a> CreateAccountLink<'a> {
pub fn new(account: AccountId, type_: AccountLinkType) -> Self {
CreateAccountLink {
account,
collect: Default::default(),
collection_options: Default::default(),
expand: Default::default(),
refresh_url: Default::default(),
return_url: Default::default(),
type_,
}
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CreateAccountLinkCollectionOptions {
pub fields: CreateAccountLinkCollectionOptionsFields,
#[serde(skip_serializing_if = "Option::is_none")]
pub future_requirements: Option<CreateAccountLinkCollectionOptionsFutureRequirements>,
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum AccountLinkCollect {
CurrentlyDue,
EventuallyDue,
}
impl AccountLinkCollect {
pub fn as_str(self) -> &'static str {
match self {
AccountLinkCollect::CurrentlyDue => "currently_due",
AccountLinkCollect::EventuallyDue => "eventually_due",
}
}
}
impl AsRef<str> for AccountLinkCollect {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for AccountLinkCollect {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for AccountLinkCollect {
fn default() -> Self {
Self::CurrentlyDue
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum AccountLinkType {
AccountOnboarding,
AccountUpdate,
}
impl AccountLinkType {
pub fn as_str(self) -> &'static str {
match self {
AccountLinkType::AccountOnboarding => "account_onboarding",
AccountLinkType::AccountUpdate => "account_update",
}
}
}
impl AsRef<str> for AccountLinkType {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for AccountLinkType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for AccountLinkType {
fn default() -> Self {
Self::AccountOnboarding
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum CreateAccountLinkCollectionOptionsFields {
CurrentlyDue,
EventuallyDue,
}
impl CreateAccountLinkCollectionOptionsFields {
pub fn as_str(self) -> &'static str {
match self {
CreateAccountLinkCollectionOptionsFields::CurrentlyDue => "currently_due",
CreateAccountLinkCollectionOptionsFields::EventuallyDue => "eventually_due",
}
}
}
impl AsRef<str> for CreateAccountLinkCollectionOptionsFields {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for CreateAccountLinkCollectionOptionsFields {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for CreateAccountLinkCollectionOptionsFields {
fn default() -> Self {
Self::CurrentlyDue
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum CreateAccountLinkCollectionOptionsFutureRequirements {
Include,
Omit,
}
impl CreateAccountLinkCollectionOptionsFutureRequirements {
pub fn as_str(self) -> &'static str {
match self {
CreateAccountLinkCollectionOptionsFutureRequirements::Include => "include",
CreateAccountLinkCollectionOptionsFutureRequirements::Omit => "omit",
}
}
}
impl AsRef<str> for CreateAccountLinkCollectionOptionsFutureRequirements {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for CreateAccountLinkCollectionOptionsFutureRequirements {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for CreateAccountLinkCollectionOptionsFutureRequirements {
fn default() -> Self {
Self::Include
}
}