/** Una cuenta bancaria: el saldo, en céntimos, nunca es negativo. */
public class BankAccount {
    private final String id;
    private long balance;               // saldo en céntimos

    public BankAccount(String id) {
        if (id == null || id.isBlank()) {
            throw new IllegalArgumentException("código vacío");
        }
        this.id = id;
        this.balance = 0;
    }

    /** Agrega dinero a la cuenta. El monto tiene que ser positivo. */
    public void deposit(long cents) {
        if (cents <= 0) {
            throw new IllegalArgumentException("monto no positivo: " + cents);
        }
        balance += cents;
    }

    /** Retira dinero si alcanza el saldo; devuelve si se pudo retirar. */
    public boolean withdraw(long cents) {
        if (cents <= 0) {
            throw new IllegalArgumentException("monto no positivo: " + cents);
        }
        if (cents > balance) {
            return false;
        }
        balance -= cents;
        return true;
    }

    public String id() {
        return id;
    }

    public long balance() {
        return balance;
    }

    @Override
    public String toString() {
        return "BankAccount[" + id + ", saldo " + balance + "]";
    }
}
