#![allow(clippy::all, clippy::pedantic, clippy::restriction)]

use beancount_pretty_printer::Config;
use beancount_pretty_printer::PrettyPrinter;
use beancount_types::Account;
use beancount_types::Amount;
use beancount_types::Commodity;
use beancount_types::Directive;
use beancount_types::Transaction;
use rust_decimal_macros::dec;
use tap::Tap as _;
use time::macros::date;

#[test]
fn pretty_printed_transaction() {
    let directives = [Directive::from(
        Transaction::on(date!(2022 - 03 - 07)).tap_mut(|transaction| {
            let commodity = Commodity::try_from("EUR").unwrap();
            transaction
                .build_posting(Account::try_from("Assets:Checking").unwrap(), |posting| {
                    posting.set_amount(Amount::new(dec!(-10000.00), commodity));
                })
                .build_posting(Account::try_from("Assets:Investment").unwrap(), |posting| {
                    posting.set_amount(Amount::new(dec!(-3000.00), commodity));
                })
                .build_posting(Account::try_from("Assets:Wallet").unwrap(), |posting| {
                    posting.set_amount(Amount::new(dec!(9000.00), commodity));
                })
                .build_posting(Account::try_from("Expenses:Banking:Fees").unwrap(), |_| {});
        }),
    )];

    let config = Config::derive_from_directives(&directives);
    let mut buffer = Vec::with_capacity(1_024);
    let mut printer = PrettyPrinter::unbuffered(config, &mut buffer);

    printer.print_directives(&directives).unwrap();

    let formatted = String::from_utf8(buffer).unwrap();
    insta::assert_display_snapshot!(formatted)
}