use super::IcIcrcAnalyticsRequest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize)]
pub enum IcIcrcAccountSort {
#[serde(rename = "id")]
Id,
#[serde(rename = "-id")]
IdDescending,
#[serde(rename = "balance")]
Balance,
#[serde(rename = "-balance")]
BalanceDescending,
#[serde(rename = "total_transactions")]
TotalTransactions,
#[serde(rename = "-total_transactions")]
TotalTransactionsDescending,
#[serde(rename = "created_timestamp")]
CreatedTimestamp,
#[serde(rename = "-created_timestamp")]
CreatedTimestampDescending,
#[serde(rename = "owner")]
Owner,
#[serde(rename = "-owner")]
OwnerDescending,
}
impl IcIcrcAccountSort {
#[must_use]
pub const fn as_api_value(self) -> &'static str {
match self {
Self::Id => "id",
Self::IdDescending => "-id",
Self::Balance => "balance",
Self::BalanceDescending => "-balance",
Self::TotalTransactions => "total_transactions",
Self::TotalTransactionsDescending => "-total_transactions",
Self::CreatedTimestamp => "created_timestamp",
Self::CreatedTimestampDescending => "-created_timestamp",
Self::Owner => "owner",
Self::OwnerDescending => "-owner",
}
}
}
impl fmt::Display for IcIcrcAccountSort {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_api_value())
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize)]
pub enum IcIcrcHolderSort {
#[serde(rename = "balance")]
Balance,
#[serde(rename = "-balance")]
BalanceDescending,
#[serde(rename = "total_transactions")]
TotalTransactions,
#[serde(rename = "-total_transactions")]
TotalTransactionsDescending,
#[serde(rename = "created_timestamp")]
CreatedTimestamp,
#[serde(rename = "-created_timestamp")]
CreatedTimestampDescending,
#[serde(rename = "principal")]
Principal,
#[serde(rename = "-principal")]
PrincipalDescending,
}
impl IcIcrcHolderSort {
#[must_use]
pub const fn as_api_value(self) -> &'static str {
match self {
Self::Balance => "balance",
Self::BalanceDescending => "-balance",
Self::TotalTransactions => "total_transactions",
Self::TotalTransactionsDescending => "-total_transactions",
Self::CreatedTimestamp => "created_timestamp",
Self::CreatedTimestampDescending => "-created_timestamp",
Self::Principal => "principal",
Self::PrincipalDescending => "-principal",
}
}
}
impl fmt::Display for IcIcrcHolderSort {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_api_value())
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcIcrcAccountListQuery {
pub owner: Option<String>,
pub after: Option<String>,
pub before: Option<String>,
pub limit: u16,
pub sort_by: IcIcrcAccountSort,
}
impl IcIcrcAccountListQuery {
#[must_use]
pub const fn new(limit: u16, sort_by: IcIcrcAccountSort) -> Self {
Self {
owner: None,
after: None,
before: None,
limit,
sort_by,
}
}
#[must_use]
pub fn with_owner(mut self, owner: impl Into<String>) -> Self {
self.owner = Some(owner.into());
self
}
#[must_use]
pub fn with_after(mut self, after: impl Into<String>) -> Self {
self.after = Some(after.into());
self
}
#[must_use]
pub fn with_before(mut self, before: impl Into<String>) -> Self {
self.before = Some(before.into());
self
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcIcrcHolderListQuery {
pub after: Option<String>,
pub before: Option<String>,
pub limit: u16,
pub sort_by: IcIcrcHolderSort,
}
impl IcIcrcHolderListQuery {
#[must_use]
pub const fn new(limit: u16, sort_by: IcIcrcHolderSort) -> Self {
Self {
after: None,
before: None,
limit,
sort_by,
}
}
#[must_use]
pub fn with_after(mut self, after: impl Into<String>) -> Self {
self.after = Some(after.into());
self
}
#[must_use]
pub fn with_before(mut self, before: impl Into<String>) -> Self {
self.before = Some(before.into());
self
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcIcrcAccountListRequest {
pub analytics: IcIcrcAnalyticsRequest,
pub query: IcIcrcAccountListQuery,
}
impl IcIcrcAccountListRequest {
#[must_use]
pub fn new(
source_endpoint: impl Into<String>,
now_unix_secs: u64,
ledger_canister_id: impl Into<String>,
query: IcIcrcAccountListQuery,
) -> Self {
Self {
analytics: IcIcrcAnalyticsRequest::new(
source_endpoint,
now_unix_secs,
ledger_canister_id,
),
query,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcIcrcAccountInfoRequest {
pub analytics: IcIcrcAnalyticsRequest,
pub account_id: String,
}
impl IcIcrcAccountInfoRequest {
#[must_use]
pub fn new(
source_endpoint: impl Into<String>,
now_unix_secs: u64,
ledger_canister_id: impl Into<String>,
account_id: impl Into<String>,
) -> Self {
Self {
analytics: IcIcrcAnalyticsRequest::new(
source_endpoint,
now_unix_secs,
ledger_canister_id,
),
account_id: account_id.into(),
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcIcrcHolderListRequest {
pub analytics: IcIcrcAnalyticsRequest,
pub query: IcIcrcHolderListQuery,
}
impl IcIcrcHolderListRequest {
#[must_use]
pub fn new(
source_endpoint: impl Into<String>,
now_unix_secs: u64,
ledger_canister_id: impl Into<String>,
query: IcIcrcHolderListQuery,
) -> Self {
Self {
analytics: IcIcrcAnalyticsRequest::new(
source_endpoint,
now_unix_secs,
ledger_canister_id,
),
query,
}
}
}