// SPDX-License-Identifier: LGPL-3.0-only // SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® export module Nostro:Account; import std; import :Currency; import :Transaction; namespace Nostro { // 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 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; }; export struct Account { std::string name; std::string bic; std::string iban; Currency currency; std::int64_t balance; // Transactions are stored per connector and account name, in a table ordered by time. std::chrono::system_clock::time_point GetLastTransactionTime(std::string_view connector) const; // Appends the ones newer than the last stored transaction, in any order. void SaveTransactions(std::string_view connector, std::vector transactions); // Newest first. std::vector 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); }; } template T> struct std::formatter : std::formatter { auto format(const Nostro::Account& obj, std::format_context& ctx) const { return std::formatter::format(std::format("{}\t{} {}\t{}", obj.name, obj.bic, obj.iban, Nostro::FormatMoney(obj.balance, obj.currency)), ctx); } };