use inquire::Text;

use crate::entities::Bank;

pub(crate) fn edit_bank(bank: &mut Option<Bank>) -> crate::database::Result<bool> {
    let orig = bank.clone();

    println!();
    println!("Add bank & tax information for invoice printouts...");
    println!();
    let mut bank_ = bank.clone().unwrap_or_default();
    bank_.name = Text::new("Bank Name?")
        .with_default(&bank_.name)
        .with_help_message("Leave empty to skip bank & tax information")
        .prompt()?;
    if !bank_.name.is_empty() {
        bank_.iban = Text::new("Int. Bank Account No. (IBAN)?")
            .with_default(&bank_.iban)
            .prompt()?;
        bank_.bic = Text::new("Business Identifier Code (BIC)?")
            .with_default(&bank_.bic)
            .prompt()?;
        *bank = Some(bank_);
    } else {
        *bank = None;
    }

    Ok(orig != *bank)
}
