package cpsc2150.banking.views;

import cpsc2150.banking.controllers.IMortgageController;
import java.util.Scanner;

public class MortgageView implements IMortgageView {

    // Private variables, controller and input
    IMortgageController controller;
    Scanner input;

    public MortgageView() {

        // Initialize scanner object
        input = new Scanner(System.in);

    }

    @Override
    public void setController(IMortgageController c) {

        // Set the private controller to the parameterized instance
        controller = c;

    }

    @Override
    public double getHouseCost() {

        // Prompt for user input
        System.out.println("How much does the house cost?");

        // Parse the double entered by the user and return it
        return (Double.parseDouble(input.nextLine()));

    }

    @Override
    public double getDownPayment() {

        // Prompt for user input
        System.out.println("How much is the down payment?");

        // Parse the double entered by the user and return it
        return (Double.parseDouble(input.nextLine()));

    }

    @Override
    public int getYears() {

        // Prompt for user input
        System.out.println("How many years?");

        // Parse the int entered by the user and return it
        return (Integer.parseInt(input.nextLine()));

    }

    @Override
    public double getMonthlyDebt() {

        // Prompt for user input
        System.out.println("How much are your monthly debt payments?");

        // Parse the double entered by the user and return it
        return (Double.parseDouble(input.nextLine()));

    }

    @Override
    public double getYearlyIncome() {

        // Prompt for user input
        System.out.println("How much is your yearly income?");

        // Parse the double entered by the user and return it
        return (Double.parseDouble(input.nextLine()));

    }

    @Override
    public int getCreditScore() {

        // Prompt for user input
        System.out.println("What is your credit score?");

        // Parse the int entered by the user and return it
        return (Integer.parseInt(input.nextLine()));

    }

    @Override
    public String getName() {

        // Prompt for user input
        System.out.println("What's your name?");

        // Return the string entered by the user
        return (input.nextLine());

    }

    @Override
    public void printToUser(String s) {

        // Print the parameterized string
        System.out.println(s);

    }

    @Override
    public void displayPayment(double p) {

        // Print the parameterized double
        System.out.println(p);

    }

    @Override
    public void displayRate(double r) {

        // Print the parameterized double
        System.out.println(r);

    }

    @Override
    public void displayApproved(boolean a) {

        // Print the parameterized boolean
        System.out.println(a);

    }

    @Override
    public boolean getAnotherMortgage() {

        // Prompt for user input
        System.out.println("Would you like to apply for another mortgage? Y/N");

        // Parse the next character entered by the user
        char answer = Character.toLowerCase(input.nextLine().charAt(0));
        // Input validation
        while (answer != 'y' && answer != 'n') {

            // Prompt for user input again
            System.out.println("Would you like to apply for another mortgage? Y/N");

            // Parse the next character entered by the user
            answer = Character.toLowerCase(input.nextLine().charAt(0));

        }

        // Determine what to return based on user input
        if (answer == 'y') {

            return true;

        } else {

            return false;

        }

    }

    @Override
    public boolean getAnotherCustomer() {

        // Prompt for user input
        System.out.println("Would you like to consider another customer? Y/N");

        // Parse the next character entered by the user
        char answer = Character.toLowerCase(input.nextLine().charAt(0));
        // Input validation
        while (answer != 'y' && answer != 'n') {

            // Prompt for user input again
            System.out.println("Would you like to consider another customer? Y/N");

            // Parse the next character entered by the user
            answer = Character.toLowerCase(input.nextLine().charAt(0));

        }

        // Determine what to return based on user input
        if (answer == 'y') {

            return true;

        } else {

            return false;

        }

    }

}
