package com.andrewlalis.perfin.model;

import java.util.function.Consumer;

/**
 * A simple pair of accounts representing the two possible linked accounts for a
 * {@link Transaction}.
 * @param creditAccount The account linked as the account to which the
 *                      transaction amount is credited.
 * @param debitAccount The account linked as the account from which the
 *                     transaction amount is debited.
 */
public record CreditAndDebitAccounts(Account creditAccount, Account debitAccount) {
    public boolean hasCredit() {
        return creditAccount != null;
    }

    public boolean hasDebit() {
        return debitAccount != null;
    }

    public void ifCredit(Consumer<Account> accountConsumer) {
        if (hasCredit()) accountConsumer.accept(creditAccount);
    }

    public void ifDebit(Consumer<Account> accountConsumer) {
        if (hasDebit()) accountConsumer.accept(debitAccount);
    }
}
