// SPDX-License-Identifier: LGPL-3.0-only // SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® export module Nostro:Transaction; import std; import :Currency; import :Utils; namespace Nostro { // Version 1 of Transaction, kept so tables written by it migrate when opened. Do not change it. struct TransactionV1 { std::string name; std::string bic; std::string iban; std::string description; Currency currency; std::int64_t amount; std::chrono::system_clock::time_point timePoint; static constexpr std::uint32_t version = 1; static constexpr auto orderedBy = &TransactionV1::timePoint; }; // Also the row type of the Crafter.DB transaction tables, so it has to stay an aggregate. The members are the // on-disk schema: changing them needs a `version` bump (with the old struct as `using Previous`), or existing // tables are refused when opened. export struct Transaction { std::string name; std::string bic; std::string iban; std::string description; Currency currency; std::int64_t amount; std::chrono::system_clock::time_point timePoint; // The bank's own id for it, so a sync that overlaps the last stored timestamp stores nothing twice. // Empty for rows stored by version 1. std::string id; // The bank's own classification, e.g. bunq's "MASTERCARD/PAYMENT" or "EBA_SDD/SDD". Empty for rows stored by version 1. std::string kind; static constexpr std::uint32_t version = 2; static constexpr auto orderedBy = &Transaction::timePoint; using Previous = TransactionV1; }; } // One line of a transaction list: local time, amount, counterparty, IBAN and description, tab separated. template<> struct std::formatter : std::formatter { auto format(const Nostro::Transaction& obj, std::format_context& ctx) const { return std::formatter::format(std::format("{}\t{}\t{}\t{}\t{}", Nostro::FormatLocalTime(obj.timePoint), Nostro::FormatMoney(obj.amount, obj.currency), obj.name, obj.iban, obj.description), ctx); } };