package com.accenture.multibank.bank;

import com.accenture.multibank.accounts.AccountModifiable;
import com.accenture.multibank.accounts.AccountType;
import com.accenture.multibank.dao.AbstractDAO;
import com.accenture.multibank.entities.AccountDAO;
import com.accenture.multibank.exceptions.AccountNotFoundException;
import com.accenture.multibank.factory.AccountFactory;
import com.accenture.multibank.generator.AccountNumberGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author manuel
 * @version 11/29/16
 */
@Service(value = "RaiffeisenBank")
public class RaiffeisenBank implements Bank {
    private final AccountDAO accountDAO2;
    private final AbstractDAO<java.lang.Integer, AccountModifiable> accountDAO;
    private final AccountNumberGenerator accountNumberGenerator;
    private final AccountFactory accountFactory;

    @Autowired
    public RaiffeisenBank(AccountDAO accountDAO2, AccountNumberGenerator accountNumberGenerator, AccountFactory accountFactory, AbstractDAO<Integer, AccountModifiable> accountDAO) {
        this.accountDAO2 = accountDAO2;
        this.accountNumberGenerator = accountNumberGenerator;
        this.accountFactory = accountFactory;
        this.accountDAO = accountDAO;
    }

    @Override
    public boolean withdraw(Integer accNr, int amount) {
        if (amount < 0)
            throw new IllegalArgumentException("Amount can't be negative in withdraw");
        return book(accNr, -amount);
    }

    private boolean book(Integer accNr, int amount) {
        AccountModifiable account = accountDAO.find(accNr);
        if (account == null)
            throw new AccountNotFoundException("Account could not be found");
        return account.book(amount);
    }

    @Override
    public boolean deposit(Integer accNr, int amount) {
        if (amount < 0)
            throw new IllegalArgumentException("Amount can't be negative in deposit");
        return book(accNr, amount);
    }

    @Override
    public boolean transfer(Integer accNrFrom, Integer accNrTo, int amount) {
        AccountModifiable from = accountDAO.find(accNrFrom),
                to = accountDAO.find(accNrTo);
        from.book(-amount);
        to.book(amount);
        return true;
    }

    @Override
    public Integer createAccount(AccountType type, int balance) {
        AccountModifiable newAccount = accountFactory.createAccount(accountNumberGenerator, type, balance);
        accountDAO.save(newAccount);
        accountDAO2.equals(null);
        return newAccount.getAccountNumber();
    }
}

@@ -196,60 +196,8 @@
 AO;%0A
-import com.accenture.multibank.entities.AccountDAO;%0A
 impo
@@ -260,16 +260,16 @@
 eption;%0A
+
 import c
@@ -623,50 +623,8 @@
 k %7B%0A
-    private final AccountDAO accountDAO2;%0A
     
@@ -859,32 +859,8 @@
 ank(
-AccountDAO accountDAO2, 
 Acco
@@ -991,48 +991,8 @@
 ) %7B%0A
-        this.accountDAO2 = accountDAO2;%0A
     
@@ -2366,42 +2366,8 @@
 t);%0A
-        accountDAO2.equals(null);%0A
     

remove dao2