package ufrn.imd.service.impl;

import lombok.extern.java.Log;
import ufrn.imd.domain.Account;
import ufrn.imd.service.DepositService;

import java.rmi.RemoteException;
import java.util.Optional;

@Log
public class DepositServiceImpl implements DepositService {

    public DepositServiceImpl() {
        super();
    }

    public void deposit(Double value, Optional<Account> acOp) throws RemoteException, RuntimeException {
        Account account = acOp.orElseThrow(() -> new RuntimeException("Null User!"));
        if(account.getBalance() < value) throw new RuntimeException("There's no money!");
        account.setBalance(account.getBalance() - value);
        log.info("deposit");
    }

}