2026-11-01 18:35:23 +01:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only
|
|
|
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
2026-10-06 15:39:17 +02:00
|
|
|
|
|
|
|
|
export module Nostro:Account;
|
|
|
|
|
|
|
|
|
|
import std;
|
|
|
|
|
import :Currency;
|
|
|
|
|
import :Transaction;
|
|
|
|
|
|
|
|
|
|
namespace Nostro {
|
2026-11-01 18:35:23 +01:00
|
|
|
// What a transaction list shows: the newest `limit` transactions that match every field. `from` and `to` are inclusive.
|
|
|
|
|
export struct TransactionQuery {
|
|
|
|
|
std::string search; // case-insensitive (ASCII), in the name, description or IBAN; empty matches all
|
|
|
|
|
std::optional<std::int64_t> amount; // exact, in the currency's minor unit, negative when outgoing
|
|
|
|
|
std::chrono::system_clock::time_point from = std::chrono::system_clock::time_point::min();
|
|
|
|
|
std::chrono::system_clock::time_point to = std::chrono::system_clock::time_point::max();
|
|
|
|
|
std::size_t limit = 100;
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-06 15:39:17 +02:00
|
|
|
export struct Account {
|
|
|
|
|
std::string name;
|
|
|
|
|
std::string bic;
|
|
|
|
|
std::string iban;
|
|
|
|
|
Currency currency;
|
|
|
|
|
std::int64_t balance;
|
2026-10-31 20:50:57 +01:00
|
|
|
|
2026-11-01 18:35:23 +01:00
|
|
|
// Transactions are stored per connector and account name, in a table ordered by time.
|
2026-10-31 20:50:57 +01:00
|
|
|
std::chrono::system_clock::time_point GetLastTransactionTime(std::string_view connector) const;
|
2026-11-01 18:35:23 +01:00
|
|
|
// Appends the ones newer than the last stored transaction, in any order.
|
|
|
|
|
void SaveTransactions(std::string_view connector, std::vector<Transaction> transactions);
|
|
|
|
|
// Newest first.
|
|
|
|
|
std::vector<Transaction> FindTransactions(std::string_view connector, const TransactionQuery& query) const;
|
|
|
|
|
|
|
|
|
|
// Deletes every table stored under `connector` (a connector's storage key covers all its accounts), closing the
|
|
|
|
|
// ones this process has open first: a table left open on deleted files would take the next sync's rows with it.
|
|
|
|
|
static void ForgetTransactions(std::string_view connector);
|
2026-10-06 15:39:17 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<std::derived_from<Nostro::Account> T>
|
|
|
|
|
struct std::formatter<T> : std::formatter<std::string> {
|
|
|
|
|
auto format(const Nostro::Account& obj, std::format_context& ctx) const {
|
2026-11-01 18:35:23 +01:00
|
|
|
return std::formatter<std::string>::format(std::format("{}\t{} {}\t{}", obj.name, obj.bic, obj.iban, Nostro::FormatMoney(obj.balance, obj.currency)), ctx);
|
2026-10-06 15:39:17 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|