use time::Date;
use crate::log::Hash;
use crate::model::{
AccountAction, AccountHandle, AccountKind, AccountPath, CaptureTime, Currency, Dimensions,
EntryId, IdempotencyKey, Label, Layer, MemoCommitment, MemoSalt, PeriodId, RecordKind, Side,
};
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ExportRow {
Leaf(LeafRow),
Entry(EntryRow),
Posting(PostingRow),
Pair(PairRow),
Document(DocumentRow),
Rate(RateRow),
Account(AccountRow),
Currency(CurrencyRow),
Seal(SealRow),
SealTotal(SealTotalRow),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct LeafRow {
pub position: u64,
pub kind: RecordKind,
pub leaf_hash: Hash,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum HoldKind {
Open,
Post,
Void,
Expire,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct EntryRow {
pub position: u64,
pub entry: EntryId,
pub key: IdempotencyKey,
pub booking_date: Date,
pub value_date: Date,
pub captured_at: Option<CaptureTime>,
pub kind: Option<Label>,
pub period: PeriodId,
pub memo_commitment: Option<MemoCommitment>,
pub memo_text: Option<String>,
pub memo_salt: Option<MemoSalt>,
pub reverses: Option<EntryId>,
pub hold_action: Option<HoldKind>,
pub hold_target: Option<EntryId>,
pub hold_expires: Option<Date>,
pub post_amount_minor: Option<i128>,
pub posting_count: u16,
pub document_count: u16,
pub rate_count: u16,
pub leaf_hash: Hash,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct PostingRow {
pub entry: EntryId,
pub position: u64,
pub index: u16,
pub account: AccountHandle,
pub path: AccountPath,
pub kind: AccountKind,
pub class: Option<Label>,
pub side: Side,
pub minor_units: i128,
pub exponent: u8,
pub currency: Currency,
pub layer: Layer,
pub dimensions: Dimensions,
pub booking_date: Date,
pub value_date: Date,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct PairRow {
pub entry: EntryId,
pub position: u64,
pub currency: Currency,
pub layer: Layer,
pub ordinal: u16,
pub debit_index: u16,
pub debit_account: AccountHandle,
pub debit_path: AccountPath,
pub credit_index: u16,
pub credit_account: AccountHandle,
pub credit_path: AccountPath,
pub minor_units: i128,
pub exponent: u8,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct DocumentRow {
pub entry: EntryId,
pub position: u64,
pub ordinal: u16,
pub doc_type: Label,
pub reference: String,
pub date: Option<Date>,
pub sha256: Option<[u8; 32]>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct RateRow {
pub entry: EntryId,
pub position: u64,
pub ordinal: u16,
pub base: Currency,
pub quote: Currency,
pub mantissa: i128,
pub exponent: i8,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct AccountRow {
pub position: u64,
pub handle: AccountHandle,
pub path: AccountPath,
pub kind: AccountKind,
pub action: AccountAction,
pub effective: Date,
pub actor: Label,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct CurrencyRow {
pub position: u64,
pub code: Currency,
pub exponent: u8,
pub effective: Date,
pub actor: Label,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct SealRow {
pub position: u64,
pub period: PeriodId,
pub start: Date,
pub end: Date,
pub through: u64,
pub account_count: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct SealTotalRow {
pub seal_position: u64,
pub currency: Currency,
pub layer: Layer,
pub root: Hash,
pub debit_minor: i128,
pub credit_minor: i128,
pub exponent: u8,
pub postings: u64,
}