import java.util.Objects;

/** Una cuenta cuyo saldo (en céntimos) nunca es negativo. */
public class BankAccount {
    private final String id;
    private long balance;

    public BankAccount(String id) {
        this.id = Objects.requireNonNull(id, "id");
    }

    public void deposit(long amount) {
        if (amount <= 0) {
            throw new IllegalArgumentException("monto no positivo: " + amount);
        }
        balance += amount;
    }

    public void withdraw(long amount) throws InsufficientFundsException {
        if (amount <= 0) {
            throw new IllegalArgumentException("monto no positivo: " + amount);
        }
        if (amount > balance) {
            throw new InsufficientFundsException(balance, amount);
        }
        balance -= amount;
        assert balance >= 0 : "invariante roto: " + balance;
    }

    public String id() {
        return id;
    }

    public long balance() {
        return balance;
    }
}
