#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::app_certified::Did;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "org.hypercerts.funding.receipt",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Receipt<S: BosStr = DefaultStr> {
pub amount: S,
pub created_at: Datetime,
pub currency: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#for: Option<AtUri<S>>,
pub from: Did<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub notes: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub occurred_at: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_network: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_rail: Option<S>,
pub to: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub transaction_id: Option<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ReceiptGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Receipt<S>,
}
impl<S: BosStr> Receipt<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, ReceiptRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ReceiptRecord;
impl XrpcResp for ReceiptRecord {
const NSID: &'static str = "org.hypercerts.funding.receipt";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = ReceiptGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<ReceiptGetRecordOutput<S>> for Receipt<S> {
fn from(output: ReceiptGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Receipt<S> {
const NSID: &'static str = "org.hypercerts.funding.receipt";
type Record = ReceiptRecord;
}
impl Collection for ReceiptRecord {
const NSID: &'static str = "org.hypercerts.funding.receipt";
type Record = ReceiptRecord;
}
impl<S: BosStr> LexiconSchema for Receipt<S> {
fn nsid() -> &'static str {
"org.hypercerts.funding.receipt"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_hypercerts_funding_receipt()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.amount;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 50usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("amount"),
max: 50usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.currency;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 10usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("currency"),
max: 10usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.notes {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 500usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("notes"),
max: 500usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.payment_network {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 50usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("payment_network"),
max: 50usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.payment_rail {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 50usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("payment_rail"),
max: 50usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.to;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2048usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("to"),
max: 2048usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.transaction_id {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 256usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("transaction_id"),
max: 256usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod receipt_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type From;
type Currency;
type To;
type CreatedAt;
type Amount;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type From = Unset;
type Currency = Unset;
type To = Unset;
type CreatedAt = Unset;
type Amount = Unset;
}
pub struct SetFrom<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetFrom<St> {}
impl<St: State> State for SetFrom<St> {
type From = Set<members::from>;
type Currency = St::Currency;
type To = St::To;
type CreatedAt = St::CreatedAt;
type Amount = St::Amount;
}
pub struct SetCurrency<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCurrency<St> {}
impl<St: State> State for SetCurrency<St> {
type From = St::From;
type Currency = Set<members::currency>;
type To = St::To;
type CreatedAt = St::CreatedAt;
type Amount = St::Amount;
}
pub struct SetTo<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTo<St> {}
impl<St: State> State for SetTo<St> {
type From = St::From;
type Currency = St::Currency;
type To = Set<members::to>;
type CreatedAt = St::CreatedAt;
type Amount = St::Amount;
}
pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
impl<St: State> State for SetCreatedAt<St> {
type From = St::From;
type Currency = St::Currency;
type To = St::To;
type CreatedAt = Set<members::created_at>;
type Amount = St::Amount;
}
pub struct SetAmount<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetAmount<St> {}
impl<St: State> State for SetAmount<St> {
type From = St::From;
type Currency = St::Currency;
type To = St::To;
type CreatedAt = St::CreatedAt;
type Amount = Set<members::amount>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct from(());
pub struct currency(());
pub struct to(());
pub struct created_at(());
pub struct amount(());
}
}
pub struct ReceiptBuilder<S: BosStr, St: receipt_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<Datetime>,
Option<S>,
Option<AtUri<S>>,
Option<Did<S>>,
Option<S>,
Option<Datetime>,
Option<S>,
Option<S>,
Option<S>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Receipt<S> {
pub fn new() -> ReceiptBuilder<S, receipt_state::Empty> {
ReceiptBuilder::new()
}
}
impl<S: BosStr> ReceiptBuilder<S, receipt_state::Empty> {
pub fn new() -> Self {
ReceiptBuilder {
_state: PhantomData,
_fields: (
None, None, None, None, None, None, None, None, None, None, None,
),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ReceiptBuilder<S, St>
where
St: receipt_state::State,
St::Amount: receipt_state::IsUnset,
{
pub fn amount(
mut self,
value: impl Into<S>,
) -> ReceiptBuilder<S, receipt_state::SetAmount<St>> {
self._fields.0 = Option::Some(value.into());
ReceiptBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ReceiptBuilder<S, St>
where
St: receipt_state::State,
St::CreatedAt: receipt_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> ReceiptBuilder<S, receipt_state::SetCreatedAt<St>> {
self._fields.1 = Option::Some(value.into());
ReceiptBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ReceiptBuilder<S, St>
where
St: receipt_state::State,
St::Currency: receipt_state::IsUnset,
{
pub fn currency(
mut self,
value: impl Into<S>,
) -> ReceiptBuilder<S, receipt_state::SetCurrency<St>> {
self._fields.2 = Option::Some(value.into());
ReceiptBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: receipt_state::State> ReceiptBuilder<S, St> {
pub fn r#for(mut self, value: impl Into<Option<AtUri<S>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_for(mut self, value: Option<AtUri<S>>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> ReceiptBuilder<S, St>
where
St: receipt_state::State,
St::From: receipt_state::IsUnset,
{
pub fn from(
mut self,
value: impl Into<Did<S>>,
) -> ReceiptBuilder<S, receipt_state::SetFrom<St>> {
self._fields.4 = Option::Some(value.into());
ReceiptBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: receipt_state::State> ReceiptBuilder<S, St> {
pub fn notes(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_notes(mut self, value: Option<S>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St: receipt_state::State> ReceiptBuilder<S, St> {
pub fn occurred_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_occurred_at(mut self, value: Option<Datetime>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St: receipt_state::State> ReceiptBuilder<S, St> {
pub fn payment_network(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_payment_network(mut self, value: Option<S>) -> Self {
self._fields.7 = value;
self
}
}
impl<S: BosStr, St: receipt_state::State> ReceiptBuilder<S, St> {
pub fn payment_rail(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_payment_rail(mut self, value: Option<S>) -> Self {
self._fields.8 = value;
self
}
}
impl<S: BosStr, St> ReceiptBuilder<S, St>
where
St: receipt_state::State,
St::To: receipt_state::IsUnset,
{
pub fn to(mut self, value: impl Into<S>) -> ReceiptBuilder<S, receipt_state::SetTo<St>> {
self._fields.9 = Option::Some(value.into());
ReceiptBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: receipt_state::State> ReceiptBuilder<S, St> {
pub fn transaction_id(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.10 = value.into();
self
}
pub fn maybe_transaction_id(mut self, value: Option<S>) -> Self {
self._fields.10 = value;
self
}
}
impl<S: BosStr, St> ReceiptBuilder<S, St>
where
St: receipt_state::State,
St::From: receipt_state::IsSet,
St::Currency: receipt_state::IsSet,
St::To: receipt_state::IsSet,
St::CreatedAt: receipt_state::IsSet,
St::Amount: receipt_state::IsSet,
{
pub fn build(self) -> Receipt<S> {
Receipt {
amount: self._fields.0.unwrap(),
created_at: self._fields.1.unwrap(),
currency: self._fields.2.unwrap(),
r#for: self._fields.3,
from: self._fields.4.unwrap(),
notes: self._fields.5,
occurred_at: self._fields.6,
payment_network: self._fields.7,
payment_rail: self._fields.8,
to: self._fields.9.unwrap(),
transaction_id: self._fields.10,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Receipt<S> {
Receipt {
amount: self._fields.0.unwrap(),
created_at: self._fields.1.unwrap(),
currency: self._fields.2.unwrap(),
r#for: self._fields.3,
from: self._fields.4.unwrap(),
notes: self._fields.5,
occurred_at: self._fields.6,
payment_network: self._fields.7,
payment_rail: self._fields.8,
to: self._fields.9.unwrap(),
transaction_id: self._fields.10,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_org_hypercerts_funding_receipt() -> LexiconDoc<'static> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("org.hypercerts.funding.receipt"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"Records a funding receipt for a payment from one user to another user. It may be recorded by the recipient, by the sender, or by a third party. The sender may remain anonymous.",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("from"), SmolStr::new_static("to"),
SmolStr::new_static("amount"),
SmolStr::new_static("currency"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("amount"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Amount of funding received as a numeric string (e.g. '1000.50').",
),
),
max_length: Some(50usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Client-declared timestamp when this receipt record was created.",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("currency"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Currency of the payment (e.g. EUR, USD, ETH).",
),
),
max_length: Some(10usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("for"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Optional reference to the activity, project, or organization this funding relates to.",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("from"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("app.certified.defs#did"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("notes"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Optional notes or additional context for this funding receipt.",
),
),
max_length: Some(500usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("occurredAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Timestamp when the payment occurred."),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("paymentNetwork"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Optional network within the payment rail (e.g. arbitrum, ethereum, sepa, visa, paypal).",
),
),
max_length: Some(50usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("paymentRail"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"How the funds were transferred (e.g. bank_transfer, credit_card, onchain, cash, check, payment_processor).",
),
),
max_length: Some(50usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("to"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The recipient of the funds. Can be identified by DID or a clear-text name.",
),
),
max_length: Some(2048usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("transactionId"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Identifier of the underlying payment transaction (e.g. bank reference, onchain transaction hash, or processor-specific ID). Use paymentNetwork to specify the network where applicable.",
),
),
max_length: Some(256usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}