package org.academiadecodigo.bootcamp11.moneyinthebank;

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */
public class Person {
    private Wallet wallet;
    private PiggyBank bank;
    private String name;

    public Person(String name, Wallet wallet, PiggyBank piggy) {
        this.name = name;
        this.wallet = wallet;
        this.bank = piggy;
    }

    public String getName() {
        return this.name;
    }

    // checkMoneyInTheBank
    public double checkMoneyInTheBank() {
        return this.bank.checkBalance();
    }

    public double checkMoneyInTheBank(boolean verbose) {
        double piggyBalance = checkMoneyInTheBank();
        if (verbose && piggyBalance > 0.0) {
            System.out.printf("Nice. Got €%.2f in da bank.\n",
                    piggyBalance);
        } else if (verbose) {
            System.out.println("Shit, who stole mah money?!\n");
        }
        System.out.println();
        return piggyBalance;
    }

    // checkWallet
    public double checkWallet() {
        return this.wallet.checkBalance();
    }

    public double checkWallet(boolean verbose) {
        double walletBalance = checkWallet();
        if (verbose && walletBalance > 0.0) {
            System.out.printf("Ooh, nice. There's €%.2f here.\n",
                    walletBalance);
        } else if (verbose) {
            System.out.println("Shit, I'm poor as fuck.\n");
        }
        System.out.println();
        return walletBalance;
    }


    // withdrawMoney
    public void withdrawMoney(double moneyToGet) {
        double moneyGotten = bank.giefMonies(moneyToGet);
        wallet.placeMoney(moneyGotten);
    }

    // depositMoney
    public void depositMoney(double moneyToTake) {
        double moneyTaken = wallet.takeMoney(moneyToTake);
        bank.addToBank(moneyTaken);
    }

    // buyBeers
    public void buyBeers(int beers, double cost) {
        double expense = wallet.takeMoney(beers * cost);
        System.out.printf("> bought %d minis, for a total of €%.2f\n",
                beers, expense);
    }

    // cry
    public boolean cry() {
        if (bank.checkBalance() == 0.0 && wallet.checkBalance() == 0.0) {
            System.out.println("I... cry... when angels deserve to DIEEEEEE");
            return true;
        }
        return false;
    }
}
